Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
#198 Subscriber 구현체 작성 (#209)
Browse files Browse the repository at this point in the history
* Feat: 주문 이벤트 listener-side의 MessageConverter 추가, Json 매퍼 추가

* Feat : 주문 이벤트 리스너 설정

* Format : Google Java Format

* Refactor : Fanout 에서 적용안되는 routing key 삭제

* Refactor : Fanout 에서 적용안되는 routing key 삭제

* Format : Google Java Format

Co-authored-by: github-actions <>
  • Loading branch information
JooHyukKim authored Mar 19, 2022
1 parent b088a5a commit 4e1bab7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.inbobwetrust.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageQueueConfig {

@Bean
public MessageConverter messageConverter(ObjectMapper objectMapper) {
return new Jackson2JsonMessageConverter(objectMapper.registerModule(new JavaTimeModule()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.inbobwetrust.subscriber;

import com.inbobwetrust.domain.Delivery;
import com.inbobwetrust.domain.ReceiverType;
import com.inbobwetrust.domain.RelayRequest;
import com.inbobwetrust.repository.RelayRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
@RequiredArgsConstructor
@Slf4j
public class DeliveryMessageSubscriber {
public static final String shopExchange = "messageQueue.exchange.shop";
public static final String agencyExchange = "messageQueue.exchange.agency";

private final RelayRepository relayRepository;

@RabbitListener(
ackMode = "MANUAL",
id = "addDeliveryMessageListener",
bindings = @QueueBinding(value = @Queue, exchange = @Exchange("messageQueue.exchange.shop")))
public Mono<Void> processAddDeliveryMessage(Delivery delivery) {
log.info("Consuming addDelivery ===> " + delivery);
return relayRepository
.save(new RelayRequest(ReceiverType.SHOP, delivery.getShopId(), delivery))
.then();
}

@RabbitListener(
ackMode = "MANUAL",
id = "setRiderMessageListener",
bindings =
@QueueBinding(value = @Queue, exchange = @Exchange("messageQueue.exchange.agency")))
public Mono<Void> processSetRiderMessage(Delivery delivery) {
log.info("Consuming setRider ===> " + delivery);
return relayRepository
.save(new RelayRequest(ReceiverType.AGENCY, delivery.getAgencyId(), delivery))
.then();
}
}

0 comments on commit 4e1bab7

Please sign in to comment.