|
1 | 1 | package mu.integration.consumer.rabbitmq;
|
2 | 2 |
|
3 |
| -import org.springframework.amqp.core.Queue; |
4 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
5 |
| -import org.springframework.context.annotation.Bean; |
6 | 4 | import org.springframework.integration.support.MessageBuilder;
|
7 | 5 | import org.springframework.messaging.Message;
|
8 | 6 | import org.springframework.messaging.MessageHeaders;
|
9 |
| -import org.springframework.messaging.handler.annotation.SendTo; |
10 | 7 | import org.springframework.stereotype.Component;
|
11 | 8 |
|
12 | 9 | /**
|
|
16 | 13 | @Component
|
17 | 14 | public class RabbitmqListener {
|
18 | 15 |
|
| 16 | + private static final String AMQ_CORRELATION_ID = "amqp_correlationId"; |
19 | 17 |
|
20 | 18 | @RabbitListener(queues = "myQueue")
|
21 |
| - @SendTo("foo_response") |
22 |
| - public Message<String> receive(Message<String> message) { |
23 |
| - |
24 |
| - System.out.println("\n\n*********************"); |
25 |
| - |
26 |
| - System.out.println(message.getHeaders()); |
27 | 19 |
|
28 |
| - Pojo record = new Pojo(); |
| 20 | + public Message<String> receive(Message<String> message) { |
29 | 21 |
|
30 |
| - String[] array = message.getPayload().split(","); |
31 |
| - record.setCol1(array[0]); |
32 |
| - record.setCol2(array[1]); |
33 |
| - record.setCol3(array[2]); |
| 22 | + System.out.println("\n\n*********** Message Received ***********"); |
34 | 23 |
|
| 24 | + //Call a service class to validate pojo |
| 25 | + Pojo record = new Pojo(message.getPayload()); |
35 | 26 | System.out.println(record.toString());
|
36 | 27 |
|
37 |
| - return MessageBuilder.withPayload("Hello") |
| 28 | + return MessageBuilder.withPayload("PROCESSED: " + message.getHeaders().get(AMQ_CORRELATION_ID)) |
38 | 29 | .setHeader(MessageHeaders.CONTENT_TYPE, "application/json")
|
39 | 30 | .build();
|
40 | 31 |
|
41 | 32 | }
|
42 | 33 |
|
43 | 34 |
|
44 |
| - @Bean |
45 |
| - public Queue queue() { |
46 |
| - return new Queue("foo_response", false); |
47 |
| - } |
48 |
| - |
49 | 35 | }
|
0 commit comments