org.springframework.amqp.core.AnonymousQueue Java Examples

The following examples show how to use org.springframework.amqp.core.AnonymousQueue. 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: SampleApplication.java    From spring-boot-graal-feature with Apache License 2.0 4 votes vote down vote up
@Bean
Queue queue() {
	return new AnonymousQueue();
}
 
Example #2
Source File: RabbitConfig.java    From SpringBootBucket with MIT License 4 votes vote down vote up
@Bean
public Queue repliesQueue() {
    return new AnonymousQueue();
}
 
Example #3
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoutingKeyExpression() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().setRoutingKeyExpression(
			spelExpressionParser.parseExpression("payload.field"));

	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	output.setBeanName("rkeProducer");
	Binding<MessageChannel> producerBinding = binder.bindProducer("rke", output,
			producerProperties);

	RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
	Queue queue = new AnonymousQueue();
	TopicExchange exchange = new TopicExchange("rke");
	org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue)
			.to(exchange).with("rkeTest");
	admin.declareQueue(queue);
	admin.declareBinding(binding);

	output.addInterceptor(new ChannelInterceptor() {

		@Override
		public Message<?> preSend(Message<?> message, MessageChannel channel) {
			assertThat(message.getHeaders()
					.get(RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER))
							.isEqualTo("rkeTest");
			return message;
		}

	});

	output.send(new GenericMessage<>(new Pojo("rkeTest")));

	Object out = spyOn(queue.getName()).receive(false);
	assertThat(out).isInstanceOf(byte[].class);
	assertThat(new String((byte[]) out, StandardCharsets.UTF_8))
			.isEqualTo("{\"field\":\"rkeTest\"}");

	producerBinding.unbind();
}
 
Example #4
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoutingKeyExpressionPartitionedAndDelay() throws Exception {
	RabbitTestBinder binder = getBinder();
	ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
	producerProperties.getExtension().setRoutingKeyExpression(
			spelExpressionParser.parseExpression("#root.getPayload().field"));
	// requires delayed message exchange plugin; tested locally
	// producerProperties.getExtension().setDelayedExchange(true);
	producerProperties.getExtension()
			.setDelayExpression(spelExpressionParser.parseExpression("1000"));
	producerProperties.setPartitionKeyExpression(new ValueExpression<>(0));

	DirectChannel output = createBindableChannel("output",
			createProducerBindingProperties(producerProperties));
	output.setBeanName("rkeProducer");
	Binding<MessageChannel> producerBinding = binder.bindProducer("rkep", output,
			producerProperties);

	RabbitAdmin admin = new RabbitAdmin(this.rabbitAvailableRule.getResource());
	Queue queue = new AnonymousQueue();
	TopicExchange exchange = new TopicExchange("rkep");
	org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue)
			.to(exchange).with("rkepTest-0");
	admin.declareQueue(queue);
	admin.declareBinding(binding);

	output.addInterceptor(new ChannelInterceptor() {

		@Override
		public Message<?> preSend(Message<?> message, MessageChannel channel) {
			assertThat(message.getHeaders()
					.get(RabbitExpressionEvaluatingInterceptor.ROUTING_KEY_HEADER))
							.isEqualTo("rkepTest");
			assertThat(message.getHeaders()
					.get(RabbitExpressionEvaluatingInterceptor.DELAY_HEADER))
							.isEqualTo(1000);
			return message;
		}

	});

	output.send(new GenericMessage<>(new Pojo("rkepTest")));

	Object out = spyOn(queue.getName()).receive(false);
	assertThat(out).isInstanceOf(byte[].class);
	assertThat(new String((byte[]) out, StandardCharsets.UTF_8))
			.isEqualTo("{\"field\":\"rkepTest\"}");

	producerBinding.unbind();
}