Search in sources :

Example 1 with DefaultMessagePropertiesConverter

use of org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter in project spring-integration by spring-projects.

the class JsonConverterCompatibilityTests method testInbound.

@Test
public void testInbound() {
    @SuppressWarnings("unchecked") final Message<String> out = (Message<String>) new ObjectToJsonTransformer().transform(new GenericMessage<Foo>(new Foo()));
    MessageProperties messageProperties = new MessageProperties();
    DefaultAmqpHeaderMapper.outboundMapper().fromHeadersToRequest(out.getHeaders(), messageProperties);
    final BasicProperties props = new DefaultMessagePropertiesConverter().fromMessageProperties(messageProperties, "UTF-8");
    this.rabbitTemplate.execute(channel -> {
        channel.basicPublish("", JSON_TESTQ, props, out.getPayload().getBytes());
        return null;
    });
    Object received = this.rabbitTemplate.receiveAndConvert(JSON_TESTQ);
    assertThat(received, instanceOf(Foo.class));
}
Also used : ObjectToJsonTransformer(org.springframework.integration.json.ObjectToJsonTransformer) GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageProperties(org.springframework.amqp.core.MessageProperties) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) DefaultMessagePropertiesConverter(org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter) Test(org.junit.Test)

Aggregations

BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Test (org.junit.Test)1 MessageProperties (org.springframework.amqp.core.MessageProperties)1 DefaultMessagePropertiesConverter (org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter)1 ObjectToJsonTransformer (org.springframework.integration.json.ObjectToJsonTransformer)1 Message (org.springframework.messaging.Message)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1