List of usage examples for org.springframework.integration.channel DirectChannel send
@Override public boolean send(Message<?> message)
From source file:com.st.si.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w ww. j av a 2s . c o m*/ */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); DefaultSftpSessionFactory sftpSessionFactory = context.getBean(DefaultSftpSessionFactory.class); SftpSession session = sftpSessionFactory.getSession(); final DirectChannel requestChannel = (DirectChannel) context.getBean("inboundMGetRecursive"); //final PollableChannel replyChannel = (PollableChannel) context.getBean("output"); try { String dir = "/HVAC - Files For Testing/"; requestChannel.send(new GenericMessage<Object>(dir + "*")); /*if (!session.exists(sftpConfiguration.getOtherRemoteDirectory())) { throw new FileNotFoundException("Remote directory does not exists... Continuing"); }*/ rename(session, dir); dir = "/HPwES - Files For Testing/"; requestChannel.send(new GenericMessage<Object>(dir + "*")); rename(session, dir); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /*final DirectChannel requestChannel = (DirectChannel) context.getBean("inboundMGetRecursive"); final PollableChannel replyChannel = (PollableChannel) context.getBean("output"); String dir = "/HVAC - Files For Testing/"; requestChannel.send(new GenericMessage<Object>(dir + "*")); Message<?> result = replyChannel.receive(1000); List<File> localFiles = (List<File>) result.getPayload(); for (File file : localFiles) { System.out.println(file.getName()); }*/ System.exit(0); }
From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java
@Test public void shouldPublishMessage() { // given//www. j a va2 s .c om DirectChannel output = new DirectChannel(); // when Binding<MessageChannel> binding = binder.bindProducer(OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties())); // then output.send(new GenericMessage<>(MESSAGE, json())); verify(hermesSender).send(any(URI.class), any(HermesMessage.class)); binding.unbind(); }
From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java
@Test public void shouldPublishMessageWithError() { // given//ww w. j a va 2 s . c o m reset(hermesSender); final HermesResponse response = HermesResponseBuilder.hermesResponse().withHttpStatus(500).build(); when(hermesSender.send(any(URI.class), any(HermesMessage.class))) .thenReturn(CompletableFuture.completedFuture(response)); DirectChannel output = new DirectChannel(); // when Binding<MessageChannel> binding = binder.bindProducer(OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties())); // then output.send(new GenericMessage<>(MESSAGE, json())); verify(hermesSender, times(4)).send(any(URI.class), any(HermesMessage.class)); binding.unbind(); }
From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinderTest.java
@Test public void shouldPublishMessageWithBytePayload() { // given/*from w ww . ja v a 2 s . c om*/ DirectChannel output = new DirectChannel(); ArgumentCaptor<URI> uriCaptor = ArgumentCaptor.forClass(URI.class); ArgumentCaptor<HermesMessage> messageCaptor = ArgumentCaptor.forClass(HermesMessage.class); // when Binding<MessageChannel> binding = binder.bindProducer(OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties())); // then output.send(new GenericMessage<>(MESSAGE, json())); verify(hermesSender).send(uriCaptor.capture(), messageCaptor.capture()); assertEquals("http://localhost:8080/topics/topic", uriCaptor.getValue().toString()); assertArrayEquals(MESSAGE.getBytes(), messageCaptor.getValue().getBody()); binding.unbind(); }
From source file:multibinder.TwoKafkaBindersApplicationTest.java
@Test public void messagingWorks() { DirectChannel dataProducer = new DirectChannel(); ((KafkaMessageChannelBinder) binderFactory.getBinder("kafka1")).bindProducer("dataIn", dataProducer, new ExtendedProducerProperties<>(new KafkaProducerProperties())); QueueChannel dataConsumer = new QueueChannel(); ((KafkaMessageChannelBinder) binderFactory.getBinder("kafka2")).bindConsumer("dataOut", UUID.randomUUID().toString(), dataConsumer, new ExtendedConsumerProperties<>(new KafkaConsumerProperties())); String testPayload = "testFoo" + UUID.randomUUID().toString(); dataProducer.send(MessageBuilder.withPayload(testPayload).build()); Message<?> receive = dataConsumer.receive(5000); Assert.assertThat(receive, Matchers.notNullValue()); Assert.assertThat(receive.getPayload(), CoreMatchers.equalTo(testPayload)); }
From source file:multibinder.RabbitAndKafkaBinderApplicationTests.java
@Test public void messagingWorks() throws Exception { // passing connection arguments arguments to the embedded Kafka instance ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class, "--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(), "--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString(), "--spring.cloud.stream.bindings.output.producer.requiredGroups=" + this.randomGroup); DirectChannel dataProducer = new DirectChannel(); BinderFactory<?> binderFactory = context.getBean(BinderFactory.class); QueueChannel dataConsumer = new QueueChannel(); ((RabbitMessageChannelBinder) binderFactory.getBinder("rabbit")).bindConsumer("dataOut", this.randomGroup, dataConsumer, new ExtendedConsumerProperties<>(new RabbitConsumerProperties())); ((KafkaMessageChannelBinder) binderFactory.getBinder("kafka")).bindProducer("dataIn", dataProducer, new ExtendedProducerProperties<>(new KafkaProducerProperties())); String testPayload = "testFoo" + this.randomGroup; dataProducer.send(MessageBuilder.withPayload(testPayload).build()); Message<?> receive = dataConsumer.receive(10000); Assert.assertThat(receive, Matchers.notNullValue()); Assert.assertThat(receive.getPayload(), CoreMatchers.equalTo(testPayload)); context.close();/* w w w . ja v a 2s . co m*/ }
From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java
@Test public void testSendAndReceive() throws Exception { Binder binder = getBinder();/*w ww. j a v a 2 s . c o m*/ BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties()); DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties); QueueChannel moduleInputChannel = new QueueChannel(); Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, outputBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, createConsumerProperties()); Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar") .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(inbound.getPayload()).isEqualTo("foo"); assertThat(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("foo/bar"); producerBinding.unbind(); consumerBinding.unbind(); }
From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java
@Test public void testSendAndReceiveMultipleTopics() throws Exception { Binder binder = getBinder();// w ww. ja v a 2 s.c om DirectChannel moduleOutputChannel1 = createBindableChannel("output1", createProducerBindingProperties(createProducerProperties())); DirectChannel moduleOutputChannel2 = createBindableChannel("output2", createProducerBindingProperties(createProducerProperties())); QueueChannel moduleInputChannel = new QueueChannel(); Binding<MessageChannel> producerBinding1 = binder.bindProducer("foo.x", moduleOutputChannel1, createProducerProperties()); Binding<MessageChannel> producerBinding2 = binder.bindProducer("foo.y", moduleOutputChannel2, createProducerProperties()); Binding<MessageChannel> consumerBinding1 = binder.bindConsumer("foo.x", "test", moduleInputChannel, createConsumerProperties()); Binding<MessageChannel> consumerBinding2 = binder.bindConsumer("foo.y", "test", moduleInputChannel, createConsumerProperties()); String testPayload1 = "foo" + UUID.randomUUID().toString(); Message<?> message1 = MessageBuilder.withPayload(testPayload1.getBytes()).build(); String testPayload2 = "foo" + UUID.randomUUID().toString(); Message<?> message2 = MessageBuilder.withPayload(testPayload2.getBytes()).build(); // Let the consumer actually bind to the producer before sending a msg binderBindUnbindLatency(); moduleOutputChannel1.send(message1); moduleOutputChannel2.send(message2); Message<?>[] messages = new Message[2]; messages[0] = receive(moduleInputChannel); messages[1] = receive(moduleInputChannel); assertThat(messages[0]).isNotNull(); assertThat(messages[1]).isNotNull(); assertThat(messages).extracting("payload").containsExactlyInAnyOrder(testPayload1.getBytes(), testPayload2.getBytes()); producerBinding1.unbind(); producerBinding2.unbind(); consumerBinding1.unbind(); consumerBinding2.unbind(); }
From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java
@Test public void testSendAndReceiveNoOriginalContentType() throws Exception { Binder binder = getBinder();//from w ww . j a v a 2 s. com BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties()); DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties); QueueChannel moduleInputChannel = new QueueChannel(); Binding<MessageChannel> producerBinding = binder.bindProducer("bar.0", moduleOutputChannel, producerBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer("bar.0", "test", moduleInputChannel, createConsumerProperties()); binderBindUnbindLatency(); Message<?> message = MessageBuilder.withPayload("foo").build(); moduleOutputChannel.send(message); Message<?> inbound = receive(moduleInputChannel); assertThat(inbound).isNotNull(); assertThat(inbound.getPayload()).isEqualTo("foo"); assertThat(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE); producerBinding.unbind(); consumerBinding.unbind(); }
From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java
@Test public void testSendAndReceiveBad() throws Exception { RabbitTestBinder binder = getBinder(); DirectChannel moduleOutputChannel = createBindableChannel("output", new BindingProperties()); DirectChannel moduleInputChannel = createBindableChannel("input", new BindingProperties()); Binding<MessageChannel> producerBinding = binder.bindProducer("bad.0", moduleOutputChannel, createProducerProperties()); Binding<MessageChannel> consumerBinding = binder.bindConsumer("bad.0", "test", moduleInputChannel, createConsumerProperties()); Message<?> message = MessageBuilder.withPayload("bad").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar") .build();//from w w w. j av a 2 s. c o m final CountDownLatch latch = new CountDownLatch(3); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { latch.countDown(); throw new RuntimeException("bad"); } }); moduleOutputChannel.send(message); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); producerBinding.unbind(); consumerBinding.unbind(); }