'rabbitMQ sender with node-red

I am trying to connect node-red with rabbitMQ. The program will recive a text with the diet that the AI chose for each day. I made the rabbitMQ Configure java file and the rabbit MQ Sender file. Here are those. The probllem is that I don't know how to do the sender file that contains the conexion: rabbitMQ Configure:

@Configuration public class RabbitMQConfig {

public static final String EXCHANGER_NAME = "Prueba";
private static final boolean DURABLE = false;
private static final boolean AUTO_DELETE = false;

public static final String ROUTING_KEY_PUESTA = "SinProcesar";
public static final String ROUTING_KEY_OBTENCION = "Procesada";

public static final String QUEUE_NAME_PUESTA="Dejar";
public static final String QUEUE_NAME_OBTENCION="Obtener";

@Bean
Queue queue1() {
    return new Queue(QUEUE_NAME_PUESTA, DURABLE);
}

@Bean
Queue queue2() {
    return new Queue(QUEUE_NAME_OBTENCION, DURABLE);
}

@Bean
DirectExchange exchange() {
    return new DirectExchange(EXCHANGER_NAME,DURABLE, AUTO_DELETE);
}

@Bean
Binding binding1(Queue queue1, DirectExchange exchange) {
    return BindingBuilder.bind(queue1).to(exchange).with(ROUTING_KEY_PUESTA);
}

@Bean
Binding binding2(Queue queue2, DirectExchange exchange) {
    return BindingBuilder.bind(queue2).to(exchange).with(ROUTING_KEY_OBTENCION);
}

/*@Bean
public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
    return new RabbitAdmin(connectionFactory);
}*/

@Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(QUEUE_NAME_OBTENCION);
    container.setMessageListener(listenerAdapter);
    container.setDefaultRequeueRejected(false);
    
    return container;
}

@Bean
Receiver receiver() {
    return new Receiver();
}

@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    return new MessageListenerAdapter(receiver, Receiver.RECEIVE_METHOD_NAME);
}




@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
    final var rabbitTemplate = new RabbitTemplate(connectionFactory);
    rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
    return rabbitTemplate;
}

@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
    return new Jackson2JsonMessageConverter();
}

}

And the rabbitMQ Sender: @Controller

public class RabbitMQSender {
    @Autowired
    private RabbitTemplate template;

    @GetMapping(value="/msg")
    public void enviarMensaje(  ) {
    
        template.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.ROUTING_KEY);
    }
}

How should I do the rabbitMQ Sender file?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source