Skip to content

Commit

Permalink
set connection factory rabbitmq
Browse files Browse the repository at this point in the history
  • Loading branch information
abd0123 committed May 19, 2024
1 parent 113339f commit 1124cb0
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand All @@ -28,6 +29,7 @@ public class ControllerMQListener {
@Autowired public ThreadPoolTaskExecutor taskExecutor;
@Autowired private ApplicationContext context;
@Autowired private RabbitListenerEndpointRegistry registry;
@Autowired private RabbitTemplate rabbitTemplate;

private static final Logger logger = LogManager.getLogger(ControllerMQListener.class);

Expand Down Expand Up @@ -122,8 +124,12 @@ public void receive(SetMessageQueueRequest in) throws Exception {
connectionFactory.setPort(in.getPort());
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");

System.out.println("Message queue set to: " + in.getHost() + ":" + in.getPort());
rabbitTemplate.setConnectionFactory(connectionFactory);
System.out.println(
"Message queue set to: "
+ rabbitTemplate.getConnectionFactory().getHost()
+ ":"
+ rabbitTemplate.getConnectionFactory().getPort());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
Expand Down

0 comments on commit 1124cb0

Please sign in to comment.