initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package de.dev089.eventproducer.producer;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TopicEventProducer {
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final String defaultRoutingKey;
|
||||
|
||||
public TopicEventProducer(
|
||||
RabbitTemplate rabbitTemplate,
|
||||
@Value("${rabbit.producer.routing-key}") String defaultRoutingKey
|
||||
) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
this.defaultRoutingKey = defaultRoutingKey;
|
||||
}
|
||||
|
||||
public void publish(String routingKey, Object payload) {
|
||||
rabbitTemplate.convertAndSend(routingKey, payload);
|
||||
}
|
||||
|
||||
public void publishToDefaultQueue(Object payload) {
|
||||
rabbitTemplate.convertAndSend(defaultRoutingKey, payload);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user