Skip to content

Instantly share code, notes, and snippets.

@arsenik
Created July 19, 2015 14:45
Show Gist options
  • Save arsenik/c513a6b3407570ca77e7 to your computer and use it in GitHub Desktop.
Save arsenik/c513a6b3407570ca77e7 to your computer and use it in GitHub Desktop.
JMS Consumer ApacheMQ
package com.jlevasseur.consumer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main( String[] args ) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("app-context.xml");
}
}
package com.jlevasseur.consumer;
public class Receiver {
public void receiveMessage(String message) {
System.out.println("Received <" + message + ">");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd">
<context:component-scan base-package="com.jlevasseur.app" />
<!-- =============================================== -->
<!-- JMS Common, Define JMS connectionFactory -->
<!-- =============================================== -->
<!-- Activemq connection factory -->
<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<constructor-arg index="0" value="tcp://0.0.0.0:61616" />
</bean>
<bean id="simpleMessageListener"
class="com.jlevasseur.consumer.Receiver"/>
<jms:listener-container
container-type="default"
connection-factory="amqConnectionFactory"
acknowledge="auto"><jms:listener destination="Send2Recv" ref="simpleMessageListener" method="receiveMessage" />
</jms:listener-container>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment