use of org.springframework.messaging.PollableChannel in project spring-integration-samples by spring-projects.
the class Application method runDemo.
private void runDemo(ConfigurableApplicationContext context) {
MessageChannel toKafka = context.getBean("toKafka", MessageChannel.class);
System.out.println("Sending 10 messages...");
Map<String, Object> headers = Collections.singletonMap(KafkaHeaders.TOPIC, this.properties.getTopic());
for (int i = 0; i < 10; i++) {
toKafka.send(new GenericMessage<>("foo" + i, headers));
}
System.out.println("Sending a null message...");
toKafka.send(new GenericMessage<>(KafkaNull.INSTANCE, headers));
PollableChannel fromKafka = context.getBean("fromKafka", PollableChannel.class);
Message<?> received = fromKafka.receive(10000);
int count = 0;
while (received != null) {
System.out.println(received);
received = fromKafka.receive(++count < 11 ? 10000 : 1000);
}
System.out.println("Adding an adapter for a second topic and sending 10 messages...");
addAnotherListenerForTopics(this.properties.getNewTopic());
headers = Collections.singletonMap(KafkaHeaders.TOPIC, this.properties.getNewTopic());
for (int i = 0; i < 10; i++) {
toKafka.send(new GenericMessage<>("bar" + i, headers));
}
received = fromKafka.receive(10000);
count = 0;
while (received != null) {
System.out.println(received);
received = fromKafka.receive(++count < 10 ? 10000 : 1000);
}
}
use of org.springframework.messaging.PollableChannel in project spring-integration-samples by spring-projects.
the class SftpInboundReceiveSample method runDemo.
@Test
public void runDemo() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpInboundReceiveSample-context.xml", this.getClass());
RemoteFileTemplate<LsEntry> template = null;
String file1 = "a.txt";
String file2 = "b.txt";
String file3 = "c.bar";
new File("local-dir", file1).delete();
new File("local-dir", file2).delete();
try {
PollableChannel localFileChannel = context.getBean("receiveChannel", PollableChannel.class);
@SuppressWarnings("unchecked") SessionFactory<LsEntry> sessionFactory = context.getBean(CachingSessionFactory.class);
template = new RemoteFileTemplate<LsEntry>(sessionFactory);
SftpTestUtils.createTestFiles(template, file1, file2, file3);
SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
adapter.start();
Message<?> received = localFileChannel.receive();
assertNotNull("Expected file", received);
System.out.println("Received first file message: " + received);
received = localFileChannel.receive();
assertNotNull("Expected file", received);
System.out.println("Received second file message: " + received);
received = localFileChannel.receive(1000);
assertNull("Expected null", received);
System.out.println("No third file was received as expected");
} finally {
SftpTestUtils.cleanUp(template, file1, file2, file3);
context.close();
assertTrue("Could note delete retrieved file", new File("local-dir", file1).delete());
assertTrue("Could note delete retrieved file", new File("local-dir", file2).delete());
}
}
use of org.springframework.messaging.PollableChannel in project spring-integration-samples by spring-projects.
the class FeedInboundChannelAdapterSample method runDemo.
@SuppressWarnings("unchecked")
@Test
public void runDemo() {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("META-INF/spring/integration/FeedInboundChannelAdapterSample-context.xml");
PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
for (int i = 0; i < 10; i++) {
Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
if (message != null) {
SyndEntry entry = message.getPayload();
System.out.println(entry.getPublishedDate() + " - " + entry.getTitle());
} else {
break;
}
}
ac.close();
}
use of org.springframework.messaging.PollableChannel in project spring-integration-samples by spring-projects.
the class HelloWorldApp method main.
public static void main(String[] args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
inputChannel.send(new GenericMessage<String>("World"));
logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
context.close();
}
use of org.springframework.messaging.PollableChannel in project spring-integration-samples by spring-projects.
the class ControlBusDemoTest method demoControlBus.
@Test
public void demoControlBus() {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/ControlBusDemo-context.xml");
MessageChannel controlChannel = ac.getBean("controlChannel", MessageChannel.class);
PollableChannel adapterOutputChanel = ac.getBean("adapterOutputChanel", PollableChannel.class);
logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
controlChannel.send(new GenericMessage<String>("@inboundAdapter.start()"));
logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
controlChannel.send(new GenericMessage<String>("@inboundAdapter.stop()"));
logger.info("Received after adapter stopped: " + adapterOutputChanel.receive(1000));
ac.close();
}
Aggregations