Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.springbootdev.examples.producer.service;
import com.springbootdev.examples.producer.model.Car;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
public class ProducerService {
private RabbitTemplate rabbitTemplate;
private static final String EXCHANGE_NAME = "vehicle_exchange";
private static final Logger logger = LoggerFactory.getLogger(ProducerService.class);
private String[] routeKeys = new String[]{
public void produce() {
for (String routingKey : routeKeys) {" sending the message with routing key {}", routingKey);
Car car = new Car(routingKey);
rabbitTemplate.convertAndSend(EXCHANGE_NAME, routingKey, car);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment