-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2f2e68
commit 9c842ef
Showing
20 changed files
with
311 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
dependencies { | ||
implementation project(":app:domain:ticketing-domain") | ||
implementation project(":app:api:common-api") | ||
|
||
//redis sub | ||
implementation 'org.springframework.data:spring-data-redis' | ||
implementation 'io.lettuce:lettuce-core:6.3.0.RELEASE' | ||
} |
36 changes: 35 additions & 1 deletion
36
app/api/ticketing-api/src/main/java/org/example/config/TicketingApiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,46 @@ | ||
package org.example.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.listener.TicketingAlertMessageListener; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.listener.ChannelTopic; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; | ||
|
||
@Configuration | ||
@Import(TicketingDomainConfig.class) | ||
@Import({ | ||
PubSubConfig.class, | ||
TicketingDomainConfig.class, | ||
TicketingAlertMessageListener.class | ||
}) | ||
@ComponentScan(basePackages = "org.example") | ||
@RequiredArgsConstructor | ||
public class TicketingApiConfig { | ||
|
||
private final MessageListener ticketingAlertMessageListener; | ||
|
||
@Bean | ||
MessageListenerAdapter ticketingAlertMessageListenerAdapter() { | ||
return new MessageListenerAdapter(ticketingAlertMessageListener); | ||
} | ||
|
||
@Bean | ||
RedisMessageListenerContainer ticketingAlertMessageListenerContainer( | ||
RedisConnectionFactory connectionFactory, | ||
MessageListenerAdapter ticketingAlertMessageListenerAdapter | ||
) { | ||
|
||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
container.setConnectionFactory(connectionFactory); | ||
container.addMessageListener( | ||
ticketingAlertMessageListenerAdapter, | ||
ChannelTopic.of("ticketingAlert") | ||
); | ||
return container; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/api/ticketing-api/src/main/java/org/example/converter/TicketingMessageConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.example.converter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.example.listener.dto.TicketingReservationMessageApiRequest; | ||
import org.springframework.data.redis.connection.Message; | ||
|
||
@Slf4j | ||
public class TicketingMessageConverter { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public static TicketingReservationMessageApiRequest toTicketingReservationMessage(Message message) { | ||
try { | ||
var convertedMessage = objectMapper.readValue( | ||
message.getBody(), | ||
TicketingReservationMessageApiRequest.class | ||
); | ||
log.info("Message published successfully to topic: {}", | ||
new String(message.getChannel())); | ||
log.info( | ||
"Subscribe Message Contents ( TicketingReservationMessageApiRequest : {} )", | ||
message); | ||
|
||
return convertedMessage; | ||
} catch (IOException e) { | ||
log.error("Failed to convert message to TicketingReservationMessageApiRequest", e); | ||
throw new IllegalArgumentException("메시지를 받지 못했습니다."); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
app/api/ticketing-api/src/main/java/org/example/listener/TicketingAlertMessageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.example.listener; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.converter.TicketingMessageConverter; | ||
import org.example.service.TicketingAlertService; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@Qualifier(value = "ticketingAlertMessageListener") | ||
public class TicketingAlertMessageListener implements MessageListener { | ||
|
||
private final TicketingAlertService ticketingAlertService; | ||
|
||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
var request = TicketingMessageConverter.toTicketingReservationMessage(message); | ||
ticketingAlertService.reserveTicketingAlert(request.toServiceRequest()); | ||
} | ||
} |
Oops, something went wrong.