Skip to content

Instantly share code, notes, and snippets.

@sophea
Created July 31, 2020 14:38
Show Gist options
  • Save sophea/337195325a7f422a5891089683cf9151 to your computer and use it in GitHub Desktop.
Save sophea/337195325a7f422a5891089683cf9151 to your computer and use it in GitHub Desktop.
package com.sma.rabbitmq.service;
import com.sma.rabbitmq.model.Category;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* Author: Mak Sophea
* Date: 07/31/2020
*/
@Service
@Slf4j
public class RabbitMQSender {
@Autowired
private AmqpTemplate rabbitTemplate;
@Value("${backend.rabbitmq.exchange}")
private String exchange;
@Value("${backend.rabbitmq.routingkey}")
private String routingkey;
public void send(Category category) {
rabbitTemplate.convertAndSend(exchange, routingkey, category);
log.info("Send msg = {} ", category);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment