Java Code Examples for org.springframework.cloud.stream.config.BindingProperties#setConsumer()

The following examples show how to use org.springframework.cloud.stream.config.BindingProperties#setConsumer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindingServiceTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerPropertiesValidation() {
	BindingServiceProperties serviceProperties = new BindingServiceProperties();
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	ConsumerProperties consumerProperties = new ConsumerProperties();
	consumerProperties.setConcurrency(0);
	props.setDestination("foo");
	props.setConsumer(consumerProperties);
	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);
	serviceProperties.setBindings(bindingProperties);
	DefaultBinderFactory binderFactory = createMockBinderFactory();
	BindingService service = new BindingService(serviceProperties, binderFactory);
	MessageChannel inputChannel = new DirectChannel();
	try {
		service.bindConsumer(inputChannel, inputChannelName);
		fail("Consumer properties should be validated.");
	}
	catch (IllegalStateException e) {
		assertThat(e)
				.hasMessageContaining("Concurrency should be greater than zero.");
	}
}
 
Example 2
Source File: KafkaStreamsBindingInformationCatalogue.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Is native decoding is enabled on this {@link KStream}.
 * @param bindingTarget binding target for KStream
 * @return true if native decoding is enabled, fasle otherwise.
 */
boolean isUseNativeDecoding(KStream<?, ?> bindingTarget) {
	BindingProperties bindingProperties = this.bindingProperties.get(bindingTarget);
	if (bindingProperties.getConsumer() == null) {
		bindingProperties.setConsumer(new ConsumerProperties());
	}
	return bindingProperties.getConsumer().isUseNativeDecoding();
}
 
Example 3
Source File: BindingServiceTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testMultipleConsumerBindingsFromIndexList() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo");

	ConsumerProperties consumer = properties.getConsumerProperties("input");
	consumer.setInstanceIndexList(Arrays.asList(0, 1));
	consumer.setInstanceCount(2);
	consumer.setPartitioned(true);
	props.setConsumer(consumer);

	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);

	properties.setBindings(bindingProperties);

	DefaultBinderFactory binderFactory = createMockBinderFactory();

	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	BindingService service = new BindingService(properties, binderFactory);
	MessageChannel inputChannel = new DirectChannel();

	Binding<MessageChannel> mockBinding1 = Mockito.mock(Binding.class, "FirstBinding");
	Binding<MessageChannel> mockBinding2 = Mockito.mock(Binding.class, "SecondBinding");

	ArgumentCaptor<ConsumerProperties> captor = ArgumentCaptor.forClass(ConsumerProperties.class);

	when(binder.bindConsumer(eq("foo"), isNull(), same(inputChannel),
		any(ConsumerProperties.class))).thenReturn(mockBinding1).thenReturn(mockBinding2);

	Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
		"input");
	assertThat(bindings).hasSize(2);

	Iterator<Binding<MessageChannel>> iterator = bindings.iterator();
	Binding<MessageChannel> binding1 = iterator.next();
	Binding<MessageChannel> binding2 = iterator.next();

	assertThat(binding1).isSameAs(mockBinding1);
	assertThat(binding2).isSameAs(mockBinding2);

	service.unbindConsumers("input");

	verify(binder, times(2)).bindConsumer(eq("foo"), isNull(), same(inputChannel),
		captor.capture());
	verify(binding1).unbind();
	verify(binding2).unbind();

	List<ConsumerProperties> allValues = captor.getAllValues();

	assertThat(allValues.size()).isEqualTo(2);

	assertThat(allValues.get(0).getInstanceIndex()).isEqualTo(0);
	assertThat(allValues.get(1).getInstanceIndex()).isEqualTo(1);

	binderFactory.destroy();
}
 
Example 4
Source File: BindingServiceTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testConsumerBindingWhenMultiplexingIsEnabled() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo,bar");

	ConsumerProperties consumer = properties.getConsumerProperties("input");
	consumer.setMultiplex(true);
	props.setConsumer(consumer);

	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);

	properties.setBindings(bindingProperties);

	DefaultBinderFactory binderFactory = createMockBinderFactory();

	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	BindingService service = new BindingService(properties, binderFactory);
	MessageChannel inputChannel = new DirectChannel();

	Binding<MessageChannel> mockBinding1 = Mockito.mock(Binding.class);

	when(binder.bindConsumer(eq("foo,bar"), isNull(), same(inputChannel),
			any(ConsumerProperties.class))).thenReturn(mockBinding1);

	Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
			"input");
	assertThat(bindings).hasSize(1);

	Iterator<Binding<MessageChannel>> iterator = bindings.iterator();
	Binding<MessageChannel> binding1 = iterator.next();

	assertThat(binding1).isSameAs(mockBinding1);

	service.unbindConsumers("input");

	verify(binder).bindConsumer(eq("foo,bar"), isNull(), same(inputChannel),
			any(ConsumerProperties.class));
	verify(binding1).unbind();

	binderFactory.destroy();
}
 
Example 5
Source File: AbstractBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
protected final BindingProperties createConsumerBindingProperties(
		CP consumerProperties) {
	BindingProperties bindingProperties = new BindingProperties();
	bindingProperties.setConsumer(consumerProperties);
	return bindingProperties;
}