Skip to content

Commit

Permalink
fix(upload-notes): fixed rabbit connection
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoSkorJjj committed Apr 23, 2024
1 parent a37afae commit bf02bf5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.core.env.Environment;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -27,9 +21,6 @@ public class RabbitMQConfig {

private static final Logger logger = LoggerFactory.getLogger(RabbitMQConfig.class);

@Autowired
private Environment env;

@Value("${app.rabbitmq.exchange}")
private String exchangeName;

Expand All @@ -45,28 +36,8 @@ public class RabbitMQConfig {
@Value("${app.rabbitmq.routingkey2}")
private String routingKey2;

@Bean
public CachingConnectionFactory rabbitConnectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
// connectionFactory.setAddresses(env.getProperty("spring.rabbitmq.addresses"));
connectionFactory.setUsername(env.getProperty("spring.rabbitmq.username"));
connectionFactory.setPassword(env.getProperty("spring.rabbitmq.password"));
connectionFactory.setHost(env.getProperty("spring.rabbitmq.host"));
connectionFactory.setPublisherReturns(true);

if (Boolean.parseBoolean(env.getProperty("spring.rabbitmq.ssl.enabled"))) {
try {
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null); // Initialize SSLContext; specify key managers and trust managers if needed
connectionFactory.getRabbitConnectionFactory().useSslProtocol(sslContext);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
logger.error("Failed to set up SSL context", e);
throw new RuntimeException("Failed to set up SSL context", e);
}
}

return connectionFactory;
}
@Autowired
private ConnectionFactory connectionFactory;

@Bean
DirectExchange exchange() {
Expand Down Expand Up @@ -95,7 +66,7 @@ Binding binding2(Queue queue2, DirectExchange exchange) {

@Bean
public RabbitAdmin rabbitAdmin() {
RabbitAdmin admin = new RabbitAdmin(rabbitConnectionFactory());
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
admin.setAutoStartup(true);
admin.declareExchange(exchange());
admin.declareQueue(queue1());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spring.rabbitmq.port=${RABBITMQ_PORT}
spring.rabbitmq.username=${RABBITMQ_USERNAME}
spring.rabbitmq.password=${RABBITMQ_PASSWORD}
spring.rabbitmq.ssl.enabled=${RABBITMQ_SSL_ENABLED}
spring.rabbitmq.ssl.algorithm=TLSv1.2
# spring.rabbitmq.ssl.algorithm=TLSv1.2
# RabbitMQ exchange and routing key
app.rabbitmq.exchange=my_exchange
app.rabbitmq.routingkey1=my_routing_key_1
Expand Down
6 changes: 6 additions & 0 deletions backend/kong-gateway/kong.deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ _format_version: "3.0"
_transform: true

services:
- name: health-check-service
routes:
- name: health-check-route
paths:
- /api/v1/healthz

- name: make-payment-service
host: make-payment
port: 50051
Expand Down

0 comments on commit bf02bf5

Please sign in to comment.