29 lines
876 B
Java
29 lines
876 B
Java
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);
|
|
}
|
|
}
|