-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
43 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/com/andrzejdubaj/rabbitmqdemoapp/RabbitMQConfig.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.andrzejdubaj.rabbitmqdemoapp; | ||
|
||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; | ||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
import org.springframework.amqp.rabbit.listener.MessageListenerContainer; | ||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class RabbitMQConfig { | ||
|
||
private static final String MY_QUEUE = "MyQueue"; | ||
|
||
@Bean | ||
Queue myQueue() { | ||
return new Queue(MY_QUEUE, true); | ||
} | ||
|
||
@Bean | ||
ConnectionFactory connectionFactory() { | ||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory("localhost"); | ||
cachingConnectionFactory.setUsername("guest"); | ||
cachingConnectionFactory.setPassword("quest"); | ||
return cachingConnectionFactory; | ||
} | ||
|
||
@Bean | ||
MessageListenerContainer messageListenerContainer() { | ||
SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer(); | ||
simpleMessageListenerContainer.setConnectionFactory(connectionFactory()); | ||
simpleMessageListenerContainer.setQueues(myQueue()); | ||
simpleMessageListenerContainer.setMessageListener(new RabbitMQMessageListener()); | ||
return simpleMessageListenerContainer; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/andrzejdubaj/rabbitmqdemoapp/RabbitMQMessageListener.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.andrzejdubaj.rabbitmqdemoapp; | ||
|
||
import org.springframework.amqp.core.Message; | ||
import org.springframework.amqp.core.MessageListener; | ||
|
||
public class RabbitMQMessageListener implements MessageListener { | ||
|
||
@Override | ||
public void onMessage(Message message){ | ||
System.out.println("message = [" + new String(message.getBody()) + "]"); | ||
} | ||
|
||
} |
16 changes: 1 addition & 15 deletions
16
src/main/java/com/andrzejdubaj/rabbitmqdemoapp/RabbitMqDemoAppApplication.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
package com.andrzejdubaj.rabbitmqdemoapp; | ||
|
||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class RabbitMqDemoAppApplication implements CommandLineRunner { | ||
|
||
@Autowired | ||
private RabbitTemplate rabbitTemplate; | ||
public class RabbitMqDemoAppApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(RabbitMqDemoAppApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
SimpleMessage simpleMessage = new SimpleMessage(); | ||
simpleMessage.setName("FirstMessage"); | ||
simpleMessage.setDescription("simpleDescription"); | ||
rabbitTemplate.convertAndSend("TestExchange", "testRouting", simpleMessage); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/main/java/com/andrzejdubaj/rabbitmqdemoapp/SimpleMessage.java
This file was deleted.
Oops, something went wrong.