| 34860 |
ranu |
1 |
package com.smartdukaan.cron.services.razorpayx;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import org.springframework.amqp.core.*;
|
|
|
5 |
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
|
|
6 |
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
|
|
7 |
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
8 |
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
9 |
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
10 |
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
|
11 |
import org.springframework.context.annotation.Bean;
|
|
|
12 |
import org.springframework.context.annotation.Configuration;
|
|
|
13 |
import org.springframework.context.annotation.Primary;
|
|
|
14 |
|
|
|
15 |
@EnableRabbit
|
|
|
16 |
@Configuration
|
|
|
17 |
public class RabbitConfig {
|
|
|
18 |
|
|
|
19 |
public static final String TXN_QUEUE = "transaction.queue";
|
|
|
20 |
public static final String TXN_EXCHANGE = "transaction.exchange";
|
|
|
21 |
public static final String TXN_ROUTING_KEY = "transaction.key";
|
|
|
22 |
|
|
|
23 |
@Bean
|
|
|
24 |
public ConnectionFactory connectionFactory() {
|
|
|
25 |
return new CachingConnectionFactory("localhost");
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
@Bean
|
|
|
29 |
public Queue transactionQueue() {
|
|
|
30 |
return new Queue(TXN_QUEUE, true);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Bean
|
|
|
34 |
public DirectExchange transactionExchange() {
|
|
|
35 |
return new DirectExchange(TXN_EXCHANGE);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
@Bean
|
|
|
39 |
public Binding transactionBinding(Queue transactionQueue, DirectExchange transactionExchange) {
|
|
|
40 |
return BindingBuilder.bind(transactionQueue)
|
|
|
41 |
.to(transactionExchange)
|
|
|
42 |
.with(TXN_ROUTING_KEY);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
@Bean
|
|
|
46 |
public Jackson2JsonMessageConverter jsonConverter() {
|
|
|
47 |
return new Jackson2JsonMessageConverter();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
@Bean
|
|
|
51 |
@Primary
|
|
|
52 |
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
|
|
53 |
RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
|
|
54 |
template.setMessageConverter(jsonConverter());
|
|
|
55 |
System.out.println(">>> RabbitTemplate is using: " + template.getMessageConverter());
|
|
|
56 |
return template;
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|