org.springframework.integration.channel.QueueChannel Java Examples

The following examples show how to use org.springframework.integration.channel.QueueChannel. 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: AbstractBinderTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
private StreamListenerMessageHandler buildStreamListener(Class<?> handlerClass,
			String handlerMethodName, Class<?>... parameters) throws Exception {
		String channelName = "reply_" + System.nanoTime();

		this.applicationContext.getBeanFactory().registerSingleton(channelName, new QueueChannel());

		Method m = ReflectionUtils.findMethod(handlerClass, handlerMethodName,
				parameters);
		InvocableHandlerMethod method = new InvocableHandlerMethod(this, m);
		HandlerMethodArgumentResolverComposite resolver = new HandlerMethodArgumentResolverComposite();
		CompositeMessageConverterFactory factory = new CompositeMessageConverterFactory();
		resolver.addResolver(new PayloadArgumentResolver(
				factory.getMessageConverterForAllRegistered()));
		method.setMessageMethodArgumentResolvers(resolver);
		Constructor<?> c = ReflectionUtils.accessibleConstructor(
				StreamListenerMessageHandler.class, InvocableHandlerMethod.class,
				boolean.class, String[].class);
		StreamListenerMessageHandler handler = (StreamListenerMessageHandler) c
				.newInstance(method, false, new String[] {});
		handler.setOutputChannelName(channelName);
		handler.setBeanFactory(this.applicationContext);
		handler.afterPropertiesSet();
//		context.refresh();
		return handler;
	}
 
Example #2
Source File: MessageConverterConfigurerTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
public void testConfigureOutputChannelWithBadContentType() {
	BindingServiceProperties props = new BindingServiceProperties();
	BindingProperties bindingProps = new BindingProperties();
	bindingProps.setContentType("application/json");
	props.setBindings(Collections.singletonMap("foo", bindingProps));
	CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(
			Collections.<MessageConverter>emptyList(), null);
	MessageConverterConfigurer configurer = new MessageConverterConfigurer(props,
			converterFactory.getMessageConverterForAllRegistered());
	QueueChannel out = new QueueChannel();
	configurer.configureOutputChannel(out, "foo");
	out.send(new GenericMessage<Foo>(new Foo(), Collections
			.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE, "bad/ct")));
	Message<?> received = out.receive(0);
	assertThat(received).isNotNull();
	assertThat(received.getPayload()).isInstanceOf(Foo.class);
}
 
Example #3
Source File: EventListenerTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeTests() {
	this.queueChannel = new QueueChannel(1);
	this.eventEmittingSkipListener = new EventEmittingSkipListener(this.queueChannel);
	this.eventEmittingItemProcessListener = new EventEmittingItemProcessListener(
			this.queueChannel);
	this.eventEmittingItemReadListener = new EventEmittingItemReadListener(
			this.queueChannel);
	this.eventEmittingItemWriteListener = new EventEmittingItemWriteListener(
			this.queueChannel);
	this.eventEmittingJobExecutionListener = new EventEmittingJobExecutionListener(
			this.queueChannel);
	this.eventEmittingStepExecutionListener = new EventEmittingStepExecutionListener(
			this.queueChannel);
	this.eventEmittingChunkListener = new EventEmittingChunkListener(
			this.queueChannel, 0);
}
 
Example #4
Source File: PartitionCapableBinderTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneRequiredGroup() throws Exception {
	B binder = getBinder();
	PP producerProperties = createProducerProperties();
	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));

	String testDestination = "testDestination"
			+ UUID.randomUUID().toString().replace("-", "");

	producerProperties.setRequiredGroups("test1");
	Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination,
			output, producerProperties);

	String testPayload = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	QueueChannel inbound1 = new QueueChannel();
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(testDestination,
			"test1", inbound1, createConsumerProperties());

	Message<?> receivedMessage1 = receive(inbound1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String((byte[]) receivedMessage1.getPayload()))
			.isEqualTo(testPayload);

	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #5
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCustomPartitionCountOverridesDefaultIfLarger() throws Exception {
	byte[] testPayload = new byte[2048];
	Arrays.fill(testPayload, (byte) 65);
	KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
	binderConfiguration.setMinPartitionCount(10);
	Binder binder = getBinder(binderConfiguration);
	QueueChannel moduleInputChannel = new QueueChannel();
	ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
	producerProperties.setPartitionCount(10);
	producerProperties.setPartitionKeyExpression(new LiteralExpression("foo"));

	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));

	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	long uniqueBindingId = System.currentTimeMillis();
	Binding<MessageChannel> producerBinding = binder.bindProducer(
			"foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			"foo" + uniqueBindingId + ".0", null, moduleInputChannel,
			consumerProperties);
	Message<?> message = org.springframework.integration.support.MessageBuilder
			.withPayload(testPayload).build();
	// Let the consumer actually bind to the producer before sending a msg
	binderBindUnbindLatency();
	moduleOutputChannel.send(message);
	Message<?> inbound = receive(moduleInputChannel);
	assertThat(inbound).isNotNull();
	assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);

	assertThat(partitionSize("foo" + uniqueBindingId + ".0")).isEqualTo(10);
	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #6
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCustomPartitionCountDoesNotOverridePartitioningIfSmaller()
		throws Exception {
	byte[] testPayload = new byte[2048];
	Arrays.fill(testPayload, (byte) 65);
	KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
	binderConfiguration.setMinPartitionCount(6);
	Binder binder = getBinder(binderConfiguration);
	QueueChannel moduleInputChannel = new QueueChannel();
	ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
	producerProperties.setPartitionCount(5);
	producerProperties.setPartitionKeyExpression(
			spelExpressionParser.parseExpression("payload"));
	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	long uniqueBindingId = System.currentTimeMillis();
	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	Binding<MessageChannel> producerBinding = binder.bindProducer(
			"foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			"foo" + uniqueBindingId + ".0", null, moduleInputChannel,
			consumerProperties);
	Thread.sleep(1000);
	Message<?> message = org.springframework.integration.support.MessageBuilder
			.withPayload(testPayload).build();
	// Let the consumer actually bind to the producer before sending a msg
	binderBindUnbindLatency();
	moduleOutputChannel.send(message);
	Message<?> inbound = receive(moduleInputChannel);
	assertThat(inbound).isNotNull();
	assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);

	assertThat(partitionSize("foo" + uniqueBindingId + ".0")).isEqualTo(6);
	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #7
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testDynamicKeyExpression() throws Exception {
	Binder binder = getBinder(createConfigurationProperties());
	QueueChannel moduleInputChannel = new QueueChannel();
	ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().getConfiguration().put("key.serializer",
			StringSerializer.class.getName());
	producerProperties.getExtension().setMessageKeyExpression(
			spelExpressionParser.parseExpression("headers.key"));
	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	String uniqueBindingId = UUID.randomUUID().toString();
	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	Binding<MessageChannel> producerBinding = binder.bindProducer(
			"foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			"foo" + uniqueBindingId + ".0", null, moduleInputChannel,
			consumerProperties);
	Thread.sleep(1000);
	Message<?> message = MessageBuilder.withPayload("somePayload")
			.setHeader("key", "myDynamicKey").build();
	// Let the consumer actually bind to the producer before sending a msg
	binderBindUnbindLatency();
	moduleOutputChannel.send(message);
	Message<?> inbound = receive(moduleInputChannel);
	assertThat(inbound).isNotNull();
	String receivedKey = new String(inbound.getHeaders()
			.get(KafkaHeaders.RECEIVED_MESSAGE_KEY, byte[].class));
	assertThat(receivedKey).isEqualTo("myDynamicKey");
	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #8
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCustomPartitionCountOverridesPartitioningIfLarger() throws Exception {
	byte[] testPayload = new byte[2048];
	Arrays.fill(testPayload, (byte) 65);
	KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
	binderConfiguration.setMinPartitionCount(4);
	Binder binder = getBinder(binderConfiguration);

	QueueChannel moduleInputChannel = new QueueChannel();
	ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
	producerProperties.setPartitionCount(5);
	producerProperties.setPartitionKeyExpression(
			spelExpressionParser.parseExpression("payload"));
	DirectChannel moduleOutputChannel = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	long uniqueBindingId = System.currentTimeMillis();
	Binding<MessageChannel> producerBinding = binder.bindProducer(
			"foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			"foo" + uniqueBindingId + ".0", null, moduleInputChannel,
			consumerProperties);
	Message<?> message = org.springframework.integration.support.MessageBuilder
			.withPayload(testPayload).build();
	// Let the consumer actually bind to the producer before sending a msg
	binderBindUnbindLatency();
	moduleOutputChannel.send(message);
	Message<?> inbound = receive(moduleInputChannel);
	assertThat(inbound).isNotNull();
	assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);
	assertThat(partitionSize("foo" + uniqueBindingId + ".0")).isEqualTo(5);
	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #9
Source File: Consumer.java    From spring-kafka-demo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "unchecked", "rawtypes" })
public static void main(String[] args) {
	ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
	rootLogger.setLevel(Level.toLevel("info"));
	
	final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONFIG, Consumer.class);
	ctx.start();

	final QueueChannel channel = ctx.getBean("inputFromKafka", QueueChannel.class);
	Message msg;		
	while((msg = channel.receive()) != null) {
		HashMap map = (HashMap)msg.getPayload();
		Set<Map.Entry> set = map.entrySet();
		for (Map.Entry entry : set) {
			String topic = (String)entry.getKey();
			System.out.println("Topic:" + topic);
			ConcurrentHashMap<Integer,List<byte[]>> messages = (ConcurrentHashMap<Integer,List<byte[]>>)entry.getValue();
			Collection<List<byte[]>> values = messages.values();
			for (Iterator<List<byte[]>> iterator = values.iterator(); iterator.hasNext();) {
				List<byte[]> list = iterator.next();
				for (byte[] object : list) {
					String message = new String(object);
					System.out.println("\tMessage: " + message);
				}
				
			}
		
		}
		
	}
	
	try {
		Thread.sleep(100000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	ctx.close();
}
 
Example #10
Source File: KafkaBinderTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPartitionedNative() throws Exception {
	Binder binder = getBinder();
	ExtendedProducerProperties<KafkaProducerProperties> properties = createProducerProperties();
	properties.setPartitionCount(6);

	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(properties));
	output.setBeanName("test.output");
	Binding<MessageChannel> outputBinding = binder.bindProducer("partNative.raw.0",
			output, properties);

	ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
	QueueChannel input0 = new QueueChannel();
	input0.setBeanName("test.inputNative");
	Binding<MessageChannel> inputBinding = binder.bindConsumer("partNative.raw.0",
			"test", input0, consumerProperties);

	output.send(new GenericMessage<>("foo".getBytes(),
			Collections.singletonMap(KafkaHeaders.PARTITION_ID, 5)));

	Message<?> received = receive(input0);
	assertThat(received).isNotNull();

	assertThat(received.getPayload()).isEqualTo("foo".getBytes());
	assertThat(received.getHeaders().get(KafkaHeaders.RECEIVED_PARTITION_ID))
			.isEqualTo(5);

	inputBinding.unbind();
	outputBinding.unbind();
}
 
Example #11
Source File: PartitionCapableBinderTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoRequiredGroups() throws Exception {
	B binder = getBinder();
	PP producerProperties = createProducerProperties();

	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));

	String testDestination = "testDestination"
			+ UUID.randomUUID().toString().replace("-", "");

	producerProperties.setRequiredGroups("test1", "test2");
	Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination,
			output, producerProperties);

	String testPayload = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	QueueChannel inbound1 = new QueueChannel();
	Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(testDestination,
			"test1", inbound1, createConsumerProperties());
	QueueChannel inbound2 = new QueueChannel();
	Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(testDestination,
			"test2", inbound2, createConsumerProperties());

	Message<?> receivedMessage1 = receive(inbound1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String((byte[]) receivedMessage1.getPayload()))
			.isEqualTo(testPayload);
	Message<?> receivedMessage2 = receive(inbound2);
	assertThat(receivedMessage2).isNotNull();
	assertThat(new String((byte[]) receivedMessage2.getPayload()))
			.isEqualTo(testPayload);

	consumerBinding1.unbind();
	consumerBinding2.unbind();
	producerBinding.unbind();
}
 
Example #12
Source File: TracingChannelInterceptorTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void errorMessageHeadersRetained() {
	this.channel.addInterceptor(this.interceptor);
	QueueChannel deadReplyChannel = new QueueChannel();
	QueueChannel errorsReplyChannel = new QueueChannel();
	Map<String, Object> errorChannelHeaders = new HashMap<>();
	errorChannelHeaders.put(MessageHeaders.REPLY_CHANNEL, errorsReplyChannel);
	errorChannelHeaders.put(MessageHeaders.ERROR_CHANNEL, errorsReplyChannel);
	this.channel.send(new ErrorMessage(
			new MessagingException(MessageBuilder.withPayload("hi")
					.setHeader("b3", "000000000000000a-000000000000000a")
					.setReplyChannel(deadReplyChannel)
					.setErrorChannel(deadReplyChannel).build()),
			errorChannelHeaders));

	this.message = this.channel.receive();

	assertThat(this.message).isNotNull();

	// Parse fails if trace or span ID are missing
	TraceContext context = parseB3SingleFormat(
			this.message.getHeaders().get("b3", String.class)).context();

	assertThat(context.traceIdString()).isEqualTo("000000000000000a");
	assertThat(context.spanIdString()).isNotEqualTo("000000000000000a");
	assertThat(this.spans).hasSize(2);
	assertThat(this.message.getHeaders().getReplyChannel())
			.isSameAs(errorsReplyChannel);
	assertThat(this.message.getHeaders().getErrorChannel())
			.isSameAs(errorsReplyChannel);
}
 
Example #13
Source File: SpringJmsApplicationTest.java    From spring-jms with MIT License 5 votes vote down vote up
@Test
public void testIntegrationGateway() {
  MessageChannel outboundOrderRequestChannel =
      applicationContext.getBean("outboundOrderRequestChannel",
          MessageChannel.class);
  QueueChannel outboundOrderResponseChannel = applicationContext
      .getBean("outboundOrderResponseChannel", QueueChannel.class);

  outboundOrderRequestChannel
      .send(new GenericMessage<>("order-001"));

  assertThat(
      outboundOrderResponseChannel.receive(5000).getPayload())
          .isEqualTo("Accepted");;
}
 
Example #14
Source File: MessageConverterConfigurerTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testConfigureOutputChannelCannotConvert() {
	BindingServiceProperties props = new BindingServiceProperties();
	BindingProperties bindingProps = new BindingProperties();
	bindingProps.setContentType("foo/bar");
	props.setBindings(Collections.singletonMap("foo", bindingProps));
	MessageConverter converter = new AbstractMessageConverter(
			new MimeType("foo", "bar")) {

		@Override
		protected boolean supports(Class<?> clazz) {
			return true;
		}

		@Override
		protected Object convertToInternal(Object payload, MessageHeaders headers,
				Object conversionHint) {
			return null;
		}

	};
	CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(
			Collections.<MessageConverter>singletonList(converter), null);
	MessageConverterConfigurer configurer = new MessageConverterConfigurer(props,
			converterFactory.getMessageConverterForAllRegistered());
	QueueChannel out = new QueueChannel();
	configurer.configureOutputChannel(out, "foo");
	try {
		out.send(new GenericMessage<Foo>(new Foo(),
				Collections.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE,
						"bad/ct")));
		fail("Expected MessageConversionException: " + out.receive(0));
	}
	catch (MessageConversionException e) {
		assertThat(e.getMessage())
				.endsWith("to the configured output type: 'foo/bar'");
	}
}
 
Example #15
Source File: KinesisBinderTests.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testBatchListener() throws Exception {
	KinesisTestBinder binder = getBinder();
	ExtendedProducerProperties<KinesisProducerProperties> producerProperties = createProducerProperties();
	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));

	Binding<MessageChannel> outputBinding = binder.bindProducer("testBatchListener",
			output, producerProperties);

	for (int i = 0; i < 3; i++) {
		output.send(new GenericMessage<>(i));
	}

	ExtendedConsumerProperties<KinesisConsumerProperties> consumerProperties = createConsumerProperties();
	consumerProperties.getExtension().setListenerMode(ListenerMode.batch);
	consumerProperties.setUseNativeDecoding(true);

	QueueChannel input = new QueueChannel();
	Binding<MessageChannel> inputBinding = binder.bindConsumer("testBatchListener",
			null, input, consumerProperties);

	Message<List<?>> receivedMessage = (Message<List<?>>) receive(input);
	assertThat(receivedMessage).isNotNull();
	assertThat(receivedMessage.getPayload().size()).isEqualTo(3);

	receivedMessage.getPayload().forEach((r) -> {
		assertThat(r).isInstanceOf(Record.class);
	});

	outputBinding.unbind();
	inputBinding.unbind();
}
 
Example #16
Source File: PublishSubscibeChannelExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsOneChannel() {
    return new QueueChannel();
}
 
Example #17
Source File: FilterExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel multipleofThreeChannel() {
    return new QueueChannel();
}
 
Example #18
Source File: PublishSubscibeChannelExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsTwoChannel() {
    return new QueueChannel();
}
 
Example #19
Source File: RouteToRecipientsExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsTwoChannel() {
    return new QueueChannel();
}
 
Example #20
Source File: RouterExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel multipleofThreeChannel() {
    return new QueueChannel();
}
 
Example #21
Source File: RouterExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsTwoChannel() {
    return new QueueChannel();
}
 
Example #22
Source File: RouterExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsOneChannel() {
    return new QueueChannel();
}
 
Example #23
Source File: EmployeeJobConfigMaster.java    From batchers with Apache License 2.0 4 votes vote down vote up
@Bean
public QueueChannel outboundRequests() {
    return new QueueChannel(clusterConfig.requests());
}
 
Example #24
Source File: PublishSubscibeChannelExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel multipleofThreeChannel() {
    return new QueueChannel();
}
 
Example #25
Source File: FilterExample.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
QueueChannel remainderIsOneChannel() {
    return new QueueChannel();
}
 
Example #26
Source File: EmployeeJobConfigSlave.java    From batchers with Apache License 2.0 4 votes vote down vote up
@Bean
public QueueChannel inboundRequests() {
    return new QueueChannel(clusterConfig.requests());
}
 
Example #27
Source File: PartitionCapableBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Test
@Ignore
public void testPartitionedModuleJava() throws Exception {
	B binder = getBinder();

	CP consumerProperties = createConsumerProperties();
	consumerProperties.setConcurrency(2);
	consumerProperties.setInstanceCount(3);
	consumerProperties.setInstanceIndex(0);
	consumerProperties.setPartitioned(true);
	QueueChannel input0 = new QueueChannel();
	input0.setBeanName("test.input0J");
	Binding<MessageChannel> input0Binding = binder.bindConsumer(
			String.format("partJ%s0", getDestinationNameDelimiter()),
			"testPartitionedModuleJava", input0, consumerProperties);
	consumerProperties.setInstanceIndex(1);
	QueueChannel input1 = new QueueChannel();
	input1.setBeanName("test.input1J");
	Binding<MessageChannel> input1Binding = binder.bindConsumer(
			String.format("partJ%s0", getDestinationNameDelimiter()),
			"testPartitionedModuleJava", input1, consumerProperties);
	consumerProperties.setInstanceIndex(2);
	QueueChannel input2 = new QueueChannel();
	input2.setBeanName("test.input2J");
	Binding<MessageChannel> input2Binding = binder.bindConsumer(
			String.format("partJ%s0", getDestinationNameDelimiter()),
			"testPartitionedModuleJava", input2, consumerProperties);

	PP producerProperties = createProducerProperties();
	producerProperties.setPartitionCount(3);
	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	output.setBeanName("test.output");
	Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output,
			producerProperties);
	if (usesExplicitRouting()) {
		Object endpoint = extractEndpoint(outputBinding);
		assertThat(getEndpointRouting(endpoint))
				.contains(getExpectedRoutingBaseDestination(
						String.format("partJ%s0", getDestinationNameDelimiter()),
						"testPartitionedModuleJava") + "-' + headers['"
						+ BinderHeaders.PARTITION_HEADER + "']");
	}

	output.send(MessageBuilder.withPayload("2")
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());
	output.send(MessageBuilder.withPayload("1")
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());
	output.send(MessageBuilder.withPayload("0")
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	Message<?> receive0 = receive(input0);
	assertThat(receive0).isNotNull();
	Message<?> receive1 = receive(input1);
	assertThat(receive1).isNotNull();
	Message<?> receive2 = receive(input2);
	assertThat(receive2).isNotNull();

	if (usesExplicitRouting()) {
		assertThat(receive0.getPayload()).isEqualTo("0".getBytes());
		assertThat(receive1.getPayload()).isEqualTo("1".getBytes());
		assertThat(receive2.getPayload()).isEqualTo("2".getBytes());
	}
	else {
		List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1,
				receive2);
		assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder(
				"0".getBytes(), "1".getBytes(), "2".getBytes());
	}

	input0Binding.unbind();
	input1Binding.unbind();
	input2Binding.unbind();
	outputBinding.unbind();
}
 
Example #28
Source File: PartitionCapableBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testAnonymousGroup() throws Exception {
	B binder = getBinder();
	BindingProperties producerBindingProperties = createProducerBindingProperties(
			createProducerProperties());
	DirectChannel output = createBindableChannel("output", producerBindingProperties);
	Binding<MessageChannel> producerBinding = binder.bindProducer(
			String.format("defaultGroup%s0", getDestinationNameDelimiter()), output,
			(PP) producerBindingProperties.getProducer());

	QueueChannel input1 = new QueueChannel();
	Binding<MessageChannel> binding1 = binder.bindConsumer(
			String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
			input1, createConsumerProperties());

	QueueChannel input2 = new QueueChannel();
	Binding<MessageChannel> binding2 = binder.bindConsumer(
			String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
			input2, createConsumerProperties());

	String testPayload1 = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload1)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String(receivedMessage1.getPayload())).isEqualTo(testPayload1);

	Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input2);
	assertThat(receivedMessage2).isNotNull();
	assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload1);

	binding2.unbind();

	String testPayload2 = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload2)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	binding2 = binder.bindConsumer(
			String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
			input2, createConsumerProperties());
	String testPayload3 = "foo-" + UUID.randomUUID().toString();
	output.send(MessageBuilder.withPayload(testPayload3)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
			.build());

	receivedMessage1 = (Message<byte[]>) receive(input1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String(receivedMessage1.getPayload())).isEqualTo(testPayload2);
	receivedMessage1 = (Message<byte[]>) receive(input1);
	assertThat(receivedMessage1).isNotNull();
	assertThat(new String(receivedMessage1.getPayload())).isNotNull();

	receivedMessage2 = (Message<byte[]>) receive(input2);
	assertThat(receivedMessage2).isNotNull();
	assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload3);

	producerBinding.unbind();
	binding1.unbind();
	binding2.unbind();
}
 
Example #29
Source File: AbstractBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void testSendPojoReceivePojoWithStreamListener() throws Exception {
	StreamListenerMessageHandler handler = this.buildStreamListener(
			AbstractBinderTests.class, "echoStation", Station.class);
	Binder binder = getBinder();

	BindingProperties producerBindingProperties = createProducerBindingProperties(
			createProducerProperties());

	DirectChannel moduleOutputChannel = createBindableChannel("output",
			producerBindingProperties);

	BindingProperties consumerBindingProperties = createConsumerBindingProperties(
			createConsumerProperties());

	DirectChannel moduleInputChannel = createBindableChannel("input",
			consumerBindingProperties);

	Binding<MessageChannel> producerBinding = binder.bindProducer(
			String.format("bad%s0f", getDestinationNameDelimiter()),
			moduleOutputChannel, producerBindingProperties.getProducer());

	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			String.format("bad%s0f", getDestinationNameDelimiter()), "test-6",
			moduleInputChannel, consumerBindingProperties.getConsumer());

	Readings r1 = new Readings();
	r1.setCustomerid("123");
	r1.setStationid("XYZ");
	Readings r2 = new Readings();
	r2.setCustomerid("546");
	r2.setStationid("ABC");
	Station station = new Station();
	station.setReadings(Arrays.asList(r1, r2));
	Message<?> message = MessageBuilder.withPayload(station)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	moduleInputChannel.subscribe(handler);
	moduleOutputChannel.send(message);

	QueueChannel channel = (QueueChannel) handler.getOutputChannel();

	Message<Station> reply = (Message<Station>) channel.receive(5000);

	assertThat(reply).isNotNull();
	assertThat(reply.getPayload() instanceof Station).isTrue();
	producerBinding.unbind();
	consumerBinding.unbind();
}
 
Example #30
Source File: AbstractBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void testSendJsonReceiveJsonWithStreamListener() throws Exception {
	StreamListenerMessageHandler handler = this.buildStreamListener(
			AbstractBinderTests.class, "echoStationString", String.class);
	Binder binder = getBinder();

	BindingProperties producerBindingProperties = createProducerBindingProperties(
			createProducerProperties());

	DirectChannel moduleOutputChannel = createBindableChannel("output",
			producerBindingProperties);

	BindingProperties consumerBindingProperties = createConsumerBindingProperties(
			createConsumerProperties());

	DirectChannel moduleInputChannel = createBindableChannel("input",
			consumerBindingProperties);

	Binding<MessageChannel> producerBinding = binder.bindProducer(
			String.format("bad%s0e", getDestinationNameDelimiter()),
			moduleOutputChannel, producerBindingProperties.getProducer());

	Binding<MessageChannel> consumerBinding = binder.bindConsumer(
			String.format("bad%s0e", getDestinationNameDelimiter()), "test-5",
			moduleInputChannel, consumerBindingProperties.getConsumer());

	String value = "{\"readings\":[{\"stationid\":\"fgh\","
			+ "\"customerid\":\"12345\",\"timestamp\":null},"
			+ "{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";

	Message<?> message = MessageBuilder.withPayload(value)
			.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
			.build();
	moduleInputChannel.subscribe(handler);
	moduleOutputChannel.send(message);

	QueueChannel channel = (QueueChannel) handler.getOutputChannel();

	Message<String> reply = (Message<String>) channel.receive(5000);

	assertThat(reply).isNotNull();
	assertThat(reply.getPayload() instanceof String).isTrue();
	producerBinding.unbind();
	consumerBinding.unbind();
}