Skip to content

Commit

Permalink
fix: 🐛 Resolving the issue where Spring Boot does not create a Rabbit…
Browse files Browse the repository at this point in the history
…MQ connection factory (#172)

* chore: infra & socket gradle version 명시

* fix: chat_exchange_properties 객체 to_string 재정의

* fix: connection factory 빈 강제 생성 옵션 추가
  • Loading branch information
psychology50 authored Oct 11, 2024
1 parent 396815d commit f46a3e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pennyway-infra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ jar { enabled = true }
dependencies {
implementation project(':pennyway-common')

/* Jackson DataType */
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.18.0'

/* jwt */
api group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.5'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.5'
Expand Down Expand Up @@ -33,11 +36,8 @@ dependencies {
/* firebase */
implementation 'com.google.firebase:firebase-admin:9.2.0'

/* Web Socket */
implementation 'org.springframework.boot:spring-boot-starter-websocket'

/* RabbitMQ */
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-amqp', version: '3.3.4'

/* TSID Generator */
implementation 'com.github.f4b6a3:tsid-creator:5.2.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ public class ChatExchangeProperties {
private final String exchange;
private final String queue;
private final String routingKey;

@Override
public String toString() {
return "ChatExchangeProperties{" +
"exchange='" + exchange + '\'' +
", queue='" + queue + '\'' +
", routingKey='" + routingKey + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
import kr.co.pennyway.infra.common.properties.ChatExchangeProperties;
import kr.co.pennyway.infra.common.properties.RabbitMqProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

@Slf4j
@EnableRabbit
@RequiredArgsConstructor
@EnableConfigurationProperties({ChatExchangeProperties.class, RabbitMqProperties.class})
Expand Down Expand Up @@ -78,6 +82,19 @@ public ConnectionFactory createConnectionFactory() {
return factory;
}

@Bean
ApplicationRunner connectionFactoryRunner(ConnectionFactory cf) {
return args -> cf.createConnection().close();
}

@Bean
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(ConnectionFactory connectionFactory, MessageConverter messageConverter) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(messageConverter);
return factory;
}

@Bean
public RabbitTemplate customRabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
Expand Down
4 changes: 2 additions & 2 deletions pennyway-socket/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies {
implementation project(':pennyway-infra')

/* Web Socket */
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version: '3.3.4'

/* Reactor Netty */
implementation "org.springframework.boot:spring-boot-starter-reactor-netty"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-reactor-netty', version: '3.3.4'
}

0 comments on commit f46a3e1

Please sign in to comment.