List of usage examples for org.springframework.amqp.core MessageProperties getDeliveryMode
public MessageDeliveryMode getDeliveryMode()
From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java
public static BasicProperties extractBasicProperties(Message message, String charset) { if (message == null || message.getMessageProperties() == null) { return null; }//from w w w. ja v a2 s. co m MessageProperties source = message.getMessageProperties(); BasicProperties target = new BasicProperties(); target.setHeaders(source.getHeaders()); target.setTimestamp(source.getTimestamp()); target.setMessageId(source.getMessageId()); target.setUserId(source.getUserId()); target.setAppId(source.getAppId()); target.setClusterId(source.getClusterId()); target.setType(source.getType()); MessageDeliveryMode deliveryMode = source.getDeliveryMode(); if (deliveryMode != null) { target.setDeliveryMode(MessageDeliveryMode.toInt(deliveryMode)); } target.setExpiration(source.getExpiration()); target.setPriority(source.getPriority()); target.setContentType(source.getContentType()); target.setContentEncoding(source.getContentEncoding()); byte[] correlationId = source.getCorrelationId(); if (correlationId != null && correlationId.length > 0) { try { target.setCorrelationId(new String(correlationId, charset)); } catch (UnsupportedEncodingException ex) { throw new AmqpUnsupportedEncodingException(ex); } } Address replyTo = source.getReplyTo(); if (replyTo != null) { target.setReplyTo(replyTo.toString()); } return target; }
From source file:org.springframework.integration.amqp.config.AmqpOutboundChannelAdapterParserTests.java
@Test public void withHeaderMapperCustomHeaders() { Object eventDrivenConsumer = context.getBean("withHeaderMapperCustomHeaders"); AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivenConsumer, "handler", AmqpOutboundEndpoint.class); assertNotNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")); assertFalse(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class)); assertEquals("42", TestUtils .getPropertyValue(endpoint, "delayExpression", org.springframework.expression.Expression.class) .getExpressionString());//from w w w . jav a 2s .c o m Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); amqpTemplateField.setAccessible(true); RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); amqpTemplate = Mockito.spy(amqpTemplate); final AtomicBoolean shouldBePersistent = new AtomicBoolean(); Mockito.doAnswer(invocation -> { Object[] args = invocation.getArguments(); org.springframework.amqp.core.Message amqpMessage = (org.springframework.amqp.core.Message) args[2]; MessageProperties properties = amqpMessage.getMessageProperties(); assertEquals("foo", properties.getHeaders().get("foo")); assertEquals("foobar", properties.getHeaders().get("foobar")); assertNull(properties.getHeaders().get("bar")); assertEquals( shouldBePersistent.get() ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT, properties.getDeliveryMode()); return null; }).when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), Mockito.any(CorrelationData.class)); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); MessageChannel requestChannel = context.getBean("requestChannel", MessageChannel.class); Message<?> message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").setHeader("bar", "bar") .setHeader("foobar", "foobar").build(); requestChannel.send(message); Mockito.verify(amqpTemplate, Mockito.times(1)).send(anyString(), isNull(), Mockito.any(org.springframework.amqp.core.Message.class), isNull()); shouldBePersistent.set(true); message = MessageBuilder.withPayload("hello").setHeader("foo", "foo").setHeader("bar", "bar") .setHeader("foobar", "foobar").setHeader(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.PERSISTENT) .build(); requestChannel.send(message); }
From source file:org.springframework.integration.amqp.config.AmqpOutboundChannelAdapterParserTests.java
@SuppressWarnings("rawtypes") @Test//w w w. ja v a2 s . c o m public void amqpOutboundChannelAdapterWithinChain() { Object eventDrivenConsumer = context.getBean("chainWithRabbitOutbound"); List chainHandlers = TestUtils.getPropertyValue(eventDrivenConsumer, "handler.handlers", List.class); AmqpOutboundEndpoint endpoint = (AmqpOutboundEndpoint) chainHandlers.get(0); assertNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")); Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate"); amqpTemplateField.setAccessible(true); RabbitTemplate amqpTemplate = TestUtils.getPropertyValue(endpoint, "amqpTemplate", RabbitTemplate.class); amqpTemplate = Mockito.spy(amqpTemplate); Mockito.doAnswer(invocation -> { Object[] args = invocation.getArguments(); org.springframework.amqp.core.Message amqpMessage = (org.springframework.amqp.core.Message) args[2]; MessageProperties properties = amqpMessage.getMessageProperties(); assertEquals("hello", new String(amqpMessage.getBody())); assertEquals(MessageDeliveryMode.PERSISTENT, properties.getDeliveryMode()); return null; }).when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(org.springframework.amqp.core.Message.class), Mockito.any(CorrelationData.class)); ReflectionUtils.setField(amqpTemplateField, endpoint, amqpTemplate); MessageChannel requestChannel = context.getBean("amqpOutboundChannelAdapterWithinChain", MessageChannel.class); Message<?> message = MessageBuilder.withPayload("hello").build(); requestChannel.send(message); Mockito.verify(amqpTemplate, Mockito.times(1)).send(Mockito.any(String.class), isNull(), Mockito.any(org.springframework.amqp.core.Message.class), isNull()); }