-
Notifications
You must be signed in to change notification settings - Fork 2
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
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>messaging</artifactId> | ||
|
||
<name>Weaver Messaging</name> | ||
|
||
<description>Messaging for Weaver</description> | ||
|
||
<parent> | ||
<groupId>edu.tamu.weaver</groupId> | ||
<artifactId>webservice-parent</artifactId> | ||
<version>2.0.0</version> | ||
</parent> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-activemq</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
25 changes: 25 additions & 0 deletions
25
messaging/src/main/java/edu/tamu/weaver/messaging/annotation/WeaverMessageListener.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,25 @@ | ||
package edu.tamu.weaver.messaging.annotation; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.core.annotation.AliasFor; | ||
import org.springframework.jms.annotation.JmsListener; | ||
|
||
@Documented | ||
@JmsListener(destination = "") | ||
@Retention(RUNTIME) | ||
@Target({METHOD, TYPE}) | ||
public @interface WeaverMessageListener { | ||
|
||
@AliasFor(annotation = JmsListener.class, attribute = "destination") | ||
String destination() default "default"; | ||
|
||
@AliasFor(annotation = JmsListener.class, attribute = "containerFactory") | ||
String containerFactory() default ""; | ||
} |
44 changes: 44 additions & 0 deletions
44
messaging/src/main/java/edu/tamu/weaver/messaging/config/MessagingConfig.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,44 @@ | ||
package edu.tamu.weaver.messaging.config; | ||
|
||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory; | ||
import org.springframework.jms.config.JmsListenerContainerFactory; | ||
import org.springframework.jms.connection.CachingConnectionFactory; | ||
import org.springframework.jms.core.JmsTemplate; | ||
|
||
@Configuration | ||
public class MessagingConfig { | ||
|
||
@Value("${spring.activemq.broker-url}") | ||
private String brokerUrl; | ||
|
||
@Bean | ||
public CachingConnectionFactory cachingConnectionFactory() { | ||
return new CachingConnectionFactory(defaultActiveMQConnectionFactory()); | ||
} | ||
|
||
@Bean | ||
public JmsTemplate jmsTopicTemplate() { | ||
JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory()); | ||
jmsTemplate.setPubSubDomain(true); | ||
return jmsTemplate; | ||
} | ||
|
||
public ActiveMQConnectionFactory defaultActiveMQConnectionFactory() { | ||
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(); | ||
activeMQConnectionFactory.setBrokerURL(brokerUrl); | ||
return activeMQConnectionFactory; | ||
} | ||
|
||
@Bean | ||
public JmsListenerContainerFactory<?> topicContainerFactory() { | ||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); | ||
factory.setConnectionFactory(defaultActiveMQConnectionFactory()); | ||
factory.setPubSubDomain(true); | ||
return factory; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
messaging/src/main/java/edu/tamu/weaver/messaging/model/MessageActions.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,5 @@ | ||
package edu.tamu.weaver.messaging.model; | ||
|
||
public interface MessageActions { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
messaging/src/main/java/edu/tamu/weaver/messaging/service/MessagingService.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,27 @@ | ||
package edu.tamu.weaver.messaging.service; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jms.core.JmsMessagingTemplate; | ||
import org.springframework.jms.core.JmsTemplate; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.support.MessageBuilder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MessagingService { | ||
|
||
private final JmsMessagingTemplate jmsTemplate; | ||
|
||
@Autowired | ||
public MessagingService(JmsTemplate jmsTopicTemplate) { | ||
this.jmsTemplate = new JmsMessagingTemplate(jmsTopicTemplate); | ||
} | ||
|
||
public void sendMessage(String destination, Map<String, String> payload) { | ||
Message<Map<String, String>> message = MessageBuilder.withPayload(payload).build(); | ||
this.jmsTemplate.send(destination, message); | ||
} | ||
|
||
} |
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