Skip to content

Commit

Permalink
Merge 6e1b0a4 into 90c59c9
Browse files Browse the repository at this point in the history
  • Loading branch information
rladdusaw authored Apr 24, 2019
2 parents 90c59c9 + 6e1b0a4 commit 32bd8f2
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
32 changes: 32 additions & 0 deletions messaging/pom.xml
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>
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 "";
}
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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package edu.tamu.weaver.messaging.model;

public interface MessageActions {

}
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);
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<module>token</module>
<module>user</module>
<module>validation</module>
<module>messaging</module>

<module>token-provider</module>

Expand Down

0 comments on commit 32bd8f2

Please sign in to comment.