# 서버 시작.
sbin/rabbitmq-server start
# 서버 중지
sbin/rabbitmqctl stop
--- spring-rabbit 연동 pom.xml
org.springframework.amqp
spring-rabbit
1.4.1.RELEASE
context-rabbitmq.xml
MqService.java
@Service
public class MqService implements MessageListener {
private static final Logger logger = LoggerFactory.getLogger(MqService.class);
private static final String TASK_QUEUE_NAME = "simple_queue";
@Autowired
private RabbitTemplate rabbitTemplate;
public void send(String message) throws IOException {
rabbitTemplate.convertAndSend(TASK_QUEUE_NAME, message);
logger.info("send message={}", message);
}
@Override
public void onMessage(Message message) {
String msg = null;
try {
msg = new String(message.getBody(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
logger.info("recv message=" + msg );
}
}
댓글 없음:
댓글 쓰기