Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created November 12, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/4191bab29de35cc750f408e20989a9a5 to your computer and use it in GitHub Desktop.
Save chathurangat/4191bab29de35cc750f408e20989a9a5 to your computer and use it in GitHub Desktop.
package com.springbootdev.examples.consumer.service;
import com.springbootdev.examples.consumer.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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class ConsumerService {
@Autowired
private RabbitTemplate rabbitTemplate;
private static final Logger logger = LoggerFactory.getLogger(ConsumerService.class);
private static final String QUEUE_NAME = "all_cars_queue";
@Scheduled(fixedRate = 5000)
public void receive()
{
Object object = rabbitTemplate.receiveAndConvert(QUEUE_NAME);
if (object != null) {
Car car = (Car) object;
logger.info(" received the message [" + car.toString() + "] ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment