Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from TAMULib/b03883-weaver-messaging-module
B03883 weaver messaging module
- Loading branch information
Showing
16 changed files
with
162 additions
and
24 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
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
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
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
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.x-MESSAGING-MODULE-SNAPSHOT</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.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) | ||
public @interface WeaverMessageListener { | ||
|
||
@AliasFor(annotation = JmsListener.class, attribute = "destination") | ||
String destination() default "default"; | ||
|
||
@AliasFor(annotation = JmsListener.class, attribute = "containerFactory") | ||
String containerFactory() default ""; | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
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.context.annotation.Profile; | ||
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 | ||
@Profile("weaver-messaging") | ||
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; | ||
} | ||
|
||
private 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/MessageAction.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 enum MessageAction { | ||
CREATE, READ, UPDATE, DELETE, REFRESH; | ||
} |
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
package edu.tamu.weaver.messaging.service; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Profile; | ||
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 | ||
@Profile("weaver-messaging") | ||
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
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
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
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
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
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
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