List of usage examples for org.springframework.integration.channel DirectChannel DirectChannel
public DirectChannel()
From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBusTests.java
@Test public void testRequestReplyReplierProperties() throws Exception { MessageBus bus = getMessageBus();//from www . j a va 2s .c om Properties properties = new Properties(); properties.put("prefix", "foo."); properties.put("deliveryMode", "NON_PERSISTENT"); properties.put("requestHeaderPatterns", "foo"); properties.put("replyHeaderPatterns", "bar"); properties.put("ackMode", "NONE"); properties.put("backOffInitialInterval", "2000"); properties.put("backOffMaxInterval", "20000"); properties.put("backOffMultiplier", "5.0"); properties.put("concurrency", "2"); properties.put("maxAttempts", "23"); properties.put("maxConcurrency", "3"); properties.put("prefix", "foo."); properties.put("prefetch", "20"); properties.put("requeue", "false"); properties.put("txSize", "10"); bus.bindReplier("props.0", new DirectChannel(), new DirectChannel(), properties); @SuppressWarnings("unchecked") List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class); assertEquals(2, bindings.size()); AbstractEndpoint endpoint = bindings.get(1).getEndpoint(); // producer assertEquals("headers['amqp_replyTo']", TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression", SpelExpression.class) .getExpressionString()); MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode", MessageDeliveryMode.class); assertEquals(MessageDeliveryMode.NON_PERSISTENT, mode); verifyFooRequestBarReplyProducer(endpoint); endpoint = bindings.get(0).getEndpoint(); // consumer verifyContainer(endpoint); verifyBarReplyConsumer(endpoint); properties.put("partitionKeyExpression", "'foo'"); properties.put("partitionKeyExtractorClass", "foo"); properties.put("partitionSelectorExpression", "0"); properties.put("partitionSelectorClass", "foo"); properties.put("partitionCount", "1"); properties.put("partitionIndex", "0"); try { bus.bindReplier("dummy", null, null, properties); fail("Expected exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), allOf(containsString("RabbitMessageBus does not support consumer properties: "), containsString("partitionCount"), containsString("partitionSelectorExpression"), containsString("partitionKeyExtractorClass"), containsString("partitionKeyExpression"), containsString("partitionSelectorClass"))); assertThat(e.getMessage(), allOf(containsString("partitionIndex"), containsString("for dummy."))); } bus.unbindConsumers("props.0"); bus.unbindProducers("props.0"); assertEquals(0, bindings.size()); }
From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBusTests.java
@Test public void testAutoBindDLQ() throws Exception { // pre-declare the queue with dead-lettering, users can also use a policy RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource()); Map<String, Object> args = new HashMap<String, Object>(); args.put("x-dead-letter-exchange", "xdbustest.DLX"); Queue queue = new Queue("xdbustest.dlqtest", true, false, false, args); admin.declareQueue(queue);/*from ww w . j a va2 s . c o m*/ MessageBus bus = getMessageBus(); Properties properties = new Properties(); properties.put("prefix", "xdbustest."); properties.put("autoBindDLQ", "true"); properties.put("maxAttempts", "1"); // disable retry properties.put("requeue", "false"); DirectChannel moduleInputChannel = new DirectChannel(); moduleInputChannel.setBeanName("dlqTest"); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { throw new RuntimeException("foo"); } }); bus.bindConsumer("dlqtest", moduleInputChannel, properties); RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource()); template.convertAndSend("", "xdbustest.dlqtest", "foo"); int n = 0; while (n++ < 100) { Object deadLetter = template.receiveAndConvert("xdbustest.dlqtest.dlq"); if (deadLetter != null) { assertEquals("foo", deadLetter); break; } Thread.sleep(100); } assertTrue(n < 100); bus.unbindConsumer("dlqtest", moduleInputChannel); admin.deleteQueue("xdbustest.dlqtest.dlq"); admin.deleteQueue("xdbustest.dlqtest"); admin.deleteExchange("xdbustest.DLX"); }
From source file:org.springframework.xd.dirt.plugins.stream.StreamPlugin.java
private void bindProducers(Module module, MessageBus bus) { DeploymentMetadata md = module.getDeploymentMetadata(); MessageChannel channel = module.getComponent("output", MessageChannel.class); if (channel != null) { if (logger.isDebugEnabled()) { logger.debug("binding output channel [" + md.getOutputChannelName() + "] for " + module); }//from w w w . jav a 2s . c om if (isChannelPubSub(md.getOutputChannelName())) { bus.bindPubSubProducer(md.getOutputChannelName(), channel); } else { bus.bindProducer(md.getOutputChannelName(), channel, md.isAliasedOutput()); } // TODO remove this once addInterceptor is an interface method in SI Object rawChannel = extractTarget(channel); // Create the tap channel now for possible future use (tap:mystream.mymodule) if (rawChannel instanceof AbstractMessageChannel) { String tapChannelName = getTapChannelName(module); DirectChannel tapChannel = new DirectChannel(); tapChannel.setBeanName(tapChannelName + ".tap.bridge"); ((AbstractMessageChannel) rawChannel).addInterceptor(new WireTap(tapChannel)); bus.bindPubSubProducer(tapChannelName, tapChannel); } else { if (logger.isDebugEnabled()) { logger.debug("output channel is not an AbstractMessageChannel. Tap will not be created."); } } } }