| 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;
|
| 34865 |
ranu |
11 |
import org.springframework.beans.factory.annotation.Value;
|
| 34860 |
ranu |
12 |
import org.springframework.context.annotation.Bean;
|
|
|
13 |
import org.springframework.context.annotation.Configuration;
|
|
|
14 |
import org.springframework.context.annotation.Primary;
|
|
|
15 |
|
|
|
16 |
@EnableRabbit
|
|
|
17 |
@Configuration
|
|
|
18 |
public class RabbitConfig {
|
|
|
19 |
|
|
|
20 |
public static final String TXN_QUEUE = "transaction.queue";
|
|
|
21 |
public static final String TXN_EXCHANGE = "transaction.exchange";
|
|
|
22 |
public static final String TXN_ROUTING_KEY = "transaction.key";
|
|
|
23 |
|
|
|
24 |
@Bean
|
| 34865 |
ranu |
25 |
public ConnectionFactory connectionFactory(
|
|
|
26 |
@Value("${spring.rabbitmq.host}") String host,
|
|
|
27 |
@Value("${spring.rabbitmq.port}") int port,
|
|
|
28 |
@Value("${spring.rabbitmq.username}") String username,
|
|
|
29 |
@Value("${spring.rabbitmq.password}") String password) {
|
|
|
30 |
|
|
|
31 |
CachingConnectionFactory factory = new CachingConnectionFactory(host, port);
|
|
|
32 |
factory.setUsername(username);
|
|
|
33 |
factory.setPassword(password);
|
|
|
34 |
return factory;
|
| 34860 |
ranu |
35 |
}
|
|
|
36 |
|
|
|
37 |
@Bean
|
|
|
38 |
public Queue transactionQueue() {
|
|
|
39 |
return new Queue(TXN_QUEUE, true);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
@Bean
|
|
|
43 |
public DirectExchange transactionExchange() {
|
|
|
44 |
return new DirectExchange(TXN_EXCHANGE);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
@Bean
|
|
|
48 |
public Binding transactionBinding(Queue transactionQueue, DirectExchange transactionExchange) {
|
|
|
49 |
return BindingBuilder.bind(transactionQueue)
|
|
|
50 |
.to(transactionExchange)
|
|
|
51 |
.with(TXN_ROUTING_KEY);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Bean
|
|
|
55 |
public Jackson2JsonMessageConverter jsonConverter() {
|
|
|
56 |
return new Jackson2JsonMessageConverter();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Bean
|
|
|
60 |
@Primary
|
|
|
61 |
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
|
|
62 |
RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
|
|
63 |
template.setMessageConverter(jsonConverter());
|
|
|
64 |
System.out.println(">>> RabbitTemplate is using: " + template.getMessageConverter());
|
|
|
65 |
return template;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|