This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.amqp.core.Message; | |
import org.springframework.amqp.core.MessagePostProcessor; | |
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | |
import org.springframework.amqp.rabbit.connection.ConnectionFactory; | |
import org.springframework.amqp.rabbit.core.RabbitTemplate; | |
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | |
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListenerSample { | |
// Adjust the header name if required, on @Header parameter | |
@RabbitListener(queues = "q.finance.invoice") | |
public void listenInvoiceCreated(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag, | |
@Header("type") String type) throws IOException { | |
if (StringUtils.equalsIgnoreCase(type, "invoice.paid")) { | |
log.info("Delegate to invoice paid handler"); | |
} else if (StringUtils.equalsIgnoreCase(type, "invoice.created")) { | |
log.info("Delegate to invoice created handler"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create RabbitMQ schema from consumer, using @RabbitListener | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.amqp.core.ExchangeTypes; | |
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to use `BindingBuilder` | |
import org.springframework.amqp.core.Binding; | |
import org.springframework.amqp.core.BindingBuilder; | |
import org.springframework.amqp.core.DirectExchange; | |
import org.springframework.amqp.core.FanoutExchange; | |
import org.springframework.amqp.core.Queue; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Topic Exchange using single method that return `Declarables` | |
import org.springframework.amqp.core.Binding; | |
import org.springframework.amqp.core.Binding.DestinationType; | |
import org.springframework.amqp.core.Declarables; | |
import org.springframework.amqp.core.Queue; | |
import org.springframework.amqp.core.TopicExchange; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Fanout Exchange using single method that return `Declarables` | |
import org.springframework.amqp.core.Binding; | |
import org.springframework.amqp.core.Binding.DestinationType; | |
import org.springframework.amqp.core.Declarables; | |
import org.springframework.amqp.core.FanoutExchange; | |
import org.springframework.amqp.core.Queue; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Direct Exchange using individual methods | |
import org.springframework.amqp.core.Binding; | |
import org.springframework.amqp.core.BindingBuilder; | |
import org.springframework.amqp.core.DirectExchange; | |
import org.springframework.amqp.core.Queue; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration |
NewerOlder