List of usage examples for org.springframework.boot.autoconfigure.amqp RabbitProperties RabbitProperties
RabbitProperties
From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java
@Override protected RabbitTestBinder getBinder() { if (testBinder == null) { testBinder = new RabbitTestBinder(rabbitAvailableRule.getResource(), new RabbitProperties()); }//from w ww. j a v a2 s .c om return testBinder; }
From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java
@Test public void testLateBinding() throws Exception { RabbitTestSupport.RabbitProxy proxy = new RabbitTestSupport.RabbitProxy(); CachingConnectionFactory cf = new CachingConnectionFactory("localhost", proxy.getPort()); RabbitMessageChannelBinder rabbitBinder = new RabbitMessageChannelBinder(cf, new RabbitProperties(), new RabbitExchangeQueueProvisioner(cf)); RabbitTestBinder binder = new RabbitTestBinder(cf, rabbitBinder); ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties(); producerProperties.getExtension().setPrefix("latebinder."); producerProperties.getExtension().setAutoBindDlq(true); MessageChannel moduleOutputChannel = createBindableChannel("output", createProducerBindingProperties(producerProperties)); Binding<MessageChannel> late0ProducerBinding = binder.bindProducer("late.0", moduleOutputChannel, producerProperties);// w w w . j av a 2s.co m QueueChannel moduleInputChannel = new QueueChannel(); ExtendedConsumerProperties<RabbitConsumerProperties> rabbitConsumerProperties = createConsumerProperties(); rabbitConsumerProperties.getExtension().setPrefix("latebinder."); Binding<MessageChannel> late0ConsumerBinding = binder.bindConsumer("late.0", "test", moduleInputChannel, rabbitConsumerProperties); producerProperties .setPartitionKeyExpression(spelExpressionParser.parseExpression("payload.equals('0') ? 0 : 1")); producerProperties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()")); producerProperties.setPartitionCount(2); MessageChannel partOutputChannel = createBindableChannel("output", createProducerBindingProperties(producerProperties)); Binding<MessageChannel> partlate0ProducerBinding = binder.bindProducer("partlate.0", partOutputChannel, producerProperties); QueueChannel partInputChannel0 = new QueueChannel(); QueueChannel partInputChannel1 = new QueueChannel(); ExtendedConsumerProperties<RabbitConsumerProperties> partLateConsumerProperties = createConsumerProperties(); partLateConsumerProperties.getExtension().setPrefix("latebinder."); partLateConsumerProperties.setPartitioned(true); partLateConsumerProperties.setInstanceIndex(0); Binding<MessageChannel> partlate0Consumer0Binding = binder.bindConsumer("partlate.0", "test", partInputChannel0, partLateConsumerProperties); partLateConsumerProperties.setInstanceIndex(1); Binding<MessageChannel> partlate0Consumer1Binding = binder.bindConsumer("partlate.0", "test", partInputChannel1, partLateConsumerProperties); ExtendedProducerProperties<RabbitProducerProperties> noDlqProducerProperties = createProducerProperties(); noDlqProducerProperties.getExtension().setPrefix("latebinder."); MessageChannel noDLQOutputChannel = createBindableChannel("output", createProducerBindingProperties(noDlqProducerProperties)); Binding<MessageChannel> noDlqProducerBinding = binder.bindProducer("lateNoDLQ.0", noDLQOutputChannel, noDlqProducerProperties); QueueChannel noDLQInputChannel = new QueueChannel(); ExtendedConsumerProperties<RabbitConsumerProperties> noDlqConsumerProperties = createConsumerProperties(); noDlqConsumerProperties.getExtension().setPrefix("latebinder."); Binding<MessageChannel> noDlqConsumerBinding = binder.bindConsumer("lateNoDLQ.0", "test", noDLQInputChannel, noDlqConsumerProperties); MessageChannel outputChannel = createBindableChannel("output", createProducerBindingProperties(noDlqProducerProperties)); Binding<MessageChannel> pubSubProducerBinding = binder.bindProducer("latePubSub", outputChannel, noDlqProducerProperties); QueueChannel pubSubInputChannel = new QueueChannel(); noDlqConsumerProperties.getExtension().setDurableSubscription(false); Binding<MessageChannel> nonDurableConsumerBinding = binder.bindConsumer("latePubSub", "lategroup", pubSubInputChannel, noDlqConsumerProperties); QueueChannel durablePubSubInputChannel = new QueueChannel(); noDlqConsumerProperties.getExtension().setDurableSubscription(true); Binding<MessageChannel> durableConsumerBinding = binder.bindConsumer("latePubSub", "lateDurableGroup", durablePubSubInputChannel, noDlqConsumerProperties); proxy.start(); moduleOutputChannel.send(new GenericMessage<>("foo")); Message<?> message = moduleInputChannel.receive(10000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isNotNull(); noDLQOutputChannel.send(new GenericMessage<>("bar")); message = noDLQInputChannel.receive(10000); assertThat(message); assertThat(message.getPayload()).isEqualTo("bar"); outputChannel.send(new GenericMessage<>("baz")); message = pubSubInputChannel.receive(10000); assertThat(message); assertThat(message.getPayload()).isEqualTo("baz"); message = durablePubSubInputChannel.receive(10000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isEqualTo("baz"); partOutputChannel.send(new GenericMessage<>("0")); partOutputChannel.send(new GenericMessage<>("1")); message = partInputChannel0.receive(10000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isEqualTo("0"); message = partInputChannel1.receive(10000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isEqualTo("1"); late0ProducerBinding.unbind(); late0ConsumerBinding.unbind(); partlate0ProducerBinding.unbind(); partlate0Consumer0Binding.unbind(); partlate0Consumer1Binding.unbind(); noDlqProducerBinding.unbind(); noDlqConsumerBinding.unbind(); pubSubProducerBinding.unbind(); nonDurableConsumerBinding.unbind(); durableConsumerBinding.unbind(); binder.cleanup(); proxy.stop(); cf.destroy(); this.rabbitAvailableRule.getResource().destroy(); }