activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dejan Bosanac <dejan.bosa...@ttmsolutions.com>
Subject Re: Problems with simple peer:// transport config & Spring
Date Thu, 31 Jul 2008 14:34:01 GMT
Hi,

peer protocol works if both apps are on the same LAN subnet. In other 
case, you'll have to configure your network statically.

-- 
Dejan Bosanac


http://www.ttmsolutions.com - get a free ActiveMQ user guide

http://www.scriptinginjava.net




new2mq wrote:
> I have what I think *must* be a simple and common deployment architecture.  
> I have two webapps running on different machines.    At any given time, one
> will receive an http request that generates an MQ message.   I want the
> other webapp on the other machine to automatically receive this message as
> well.
>
> My understanding is that the peer protocol should fit the bill just fine.  
> My problem is that even in the simplest example I can write, on the same
> network segment, I can't get it to work (i.e. messages sent by one VM are
> also received by the that VM, but not by the other).   It works if both VMs
> are on the same box, but that's a deal-breaker for me.
>
> I've (obiously) had trouble connecting the dots here.  For instance, I see
> configuration for brokers that allows one to specify the networkConnector
> and transportConnector; places where discoveryUri looks promising.   But I
> thought that the peer protocol created an embedded broker on the fly -- so
> how is that configured?  Also, connecting Spring config with the activemq
> config (without xbean) has been frustrating.
>
> Here's my Spring config:
> ////////////////////////
> // spring-config.xml
> ///////////////////////
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
> "http://www.springframework.org/dtd/spring-beans.dtd">
> <beans>
>     <bean id="jmsTopicConnectionFactory"
>    class="org.apache.activemq.ActiveMQConnectionFactory">
>         <property name="brokerURL">
>             <value>peer://mygroupname/mybrokername</value>
>         </property>
>     </bean>	
>     
>     <bean id="TestTopic" class="org.apache.activemq.command.ActiveMQTopic">
>         <constructor-arg>
>             <value>TestTopic</value>
>         </constructor-arg>	
>     </bean>
>     
>     
>     <bean id="SenderBean" class="com.ssi.exp.TestMessageSender">			
>         <property name="jmsTemplate">
>             <ref bean="TestTopicJmsTemplate"/>
>         </property>
>     </bean> 		
>     
>     <bean id="MessageListener" class="com.ssi.exp.TestMessageListener" />
>     
>     <bean id="TestJmsTopicListenerContainer"
> class="org.springframework.jms.listener.DefaultMessageListenerContainer102">
>         <property name="concurrentConsumers">
>             <value>1</value>
>         </property>
>         <property name="connectionFactory" ref="jmsTopicConnectionFactory"/>
>         <property name="destination" ref="TestTopic" />
>         <property name="messageListener" ref="MessageListener" />
>         <property name="pubSubDomain">
>             <value>true</value>
>         </property>
>     </bean>		
>     
>     <bean id="TestTopicJmsTemplate"
> class="org.springframework.jms.core.JmsTemplate102">
>         <property name="connectionFactory">
>             <ref bean="jmsTopicConnectionFactory" />
>         </property>
>         <property name="defaultDestination">
>             <ref bean="TestTopic" />
>         </property>
>         <property name="pubSubDomain">
>             <value>true</value>
>         </property>
>     </bean>
> </beans> 		
>
> All my test code does is load the Spring context.   The test app can be run
> as listener-only or as sender-listener.
>
>
> ////////////////////////
> // Test Code: TestAMQPeer.java
> ///////////////////////
> package com.ssi.exp;
>
>
> import java.util.Map;
> import java.util.HashMap;
>
> import org.springframework.context.support.ClassPathXmlApplicationContext;
> import org.springframework.context.ApplicationContext;
>
> public class TestAMQPeer {
>
> 	public static void main(String[] cmdArgs) throws Exception {
> 	
> 		System.out.println("Loading Spring context...");
> 		System.out.println("\tThis should create the activemq listener and
> sender...");
>                 
>                 // load the Spring app ctx
>                 // listeners should be registered automatically
>                 // per my understanding
> 		ApplicationContext ctx = new
> ClassPathXmlApplicationContext("spring-config.xml");
> 		
>                 // defaults
>                 int numMsgs = 5; // send 10 messages
> 		int delay = 3; // seconds
> 		
> 		// listen only by default
> 		if ( cmdArgs.length > 0 && null != cmdArgs[0] &&
> cmdArgs[0].equalsIgnoreCase("send") ) {
>                         // if running as a sender, start sending messages
>                         // this process should receive them, and any other
>                         // in the peer group
>                         System.out.println("Executing in SENDER mode...");
> 			TestMessageSender sender = (TestMessageSender) ctx.getBean("SenderBean");
> 			for (int i = 0; i < numMsgs; i++) {
> 				sender.send();
> 				try { Thread.sleep(delay * 1000l); } catch (InterruptedException ie) {};
> // ignore
> 			}
> 		}
> 		
> 	}
> }	
>
> ////////////////////////
> // Listen-only output (on machine A)
> ///////////////////////
> [goodacre@VM-QA-701-ENT ~]$ /opt/bea/jdk150_06/bin/java -jar
> test-amq-peer.jar 
> Loading Spring context...
>         This should create the activemq listener and sender...
> Jul 31, 2008 9:15:07 AM
> org.springframework.context.support.AbstractApplicationContext
> prepareRefresh
> INFO: Refreshing
> org.springframework.context.support.ClassPathXmlApplicationContext@3eca90:
> display name
> [org.springframework.context.support.ClassPathXmlApplicationContext@3eca90];
> startup date [Thu Jul 31 09:15:07 CDT 2008]; root of context hierarchy
> Jul 31, 2008 9:15:07 AM
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader
> loadBeanDefinitions
> INFO: Loading XML bean definitions from class path resource
> [spring-config.xml]
> Jul 31, 2008 9:15:07 AM
> org.springframework.context.support.AbstractApplicationContext
> obtainFreshBeanFactory
> INFO: Bean factory for application context
> [org.springframework.context.support.ClassPathXmlApplicationContext@3eca90]:
> org.springframework.beans.factory.support.DefaultListableBeanFactory@1df280b
> Jul 31, 2008 9:15:07 AM
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> preInstantiateSingletons
> INFO: Pre-instantiating singletons in
> org.springframework.beans.factory.support.DefaultListableBeanFactory@1df280b:
> defining beans
> [jmsTopicConnectionFactory,TestTopic,SenderBean,MessageListener,TestJmsTopicListenerContainer,TestTopicJmsTemplate];
> root of factory hierarchy
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.BrokerService getBroker
> INFO: ActiveMQ 4.0.1 JMS Message Broker (mybrokername) is starting
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.BrokerService getBroker
> INFO: For help or more information please see:
> http://incubator.apache.org/activemq/
> Jul 31, 2008 9:15:08 AM
> org.apache.activemq.transport.TransportServerThreadSupport doStart
> INFO: Listening for connections at: tcp://VM-QA-701-ENT:54820
> Jul 31, 2008 9:15:08 AM
> org.apache.activemq.transport.discovery.multicast.MulticastDiscoveryAgent
> start
> WARNING: brokerName not set
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.TransportConnector start
> INFO: Connector tcp://VM-QA-701-ENT:54820 Started
> Jul 31, 2008 9:15:08 AM org.apache.activemq.network.NetworkConnector doStart
> INFO: Network Connector bridge Started
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.BrokerService start
> INFO: ActiveMQ JMS Message Broker (mybrokername,
> ID:VM-QA-701-ENT-54819-1217513708221-1:0) started
> Jul 31, 2008 9:15:08 AM org.apache.activemq.transport.vm.VMTransportFactory
> bind
> INFO: binding to broker: mybrokername
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.TransportConnector start
> INFO: Connector vm://mybrokername Started
> Jul 31, 2008 9:15:08 AM org.apache.activemq.broker.jmx.ManagementContext$1
> run
> INFO: JMX consoles can connect to
> service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
>
>
> ////////////////////////
> // Sender-Listener output (on machine B)
> ///////////////////////
> [goodacre@dacar-collector ~]$ /opt/java/bin/java -jar test-amq-peer.jar send
> Loading Spring context...
>         This should create the activemq listener and sender...
> Jul 31, 2008 2:03:35 AM
> org.springframework.context.support.AbstractApplicationContext
> prepareRefresh
> INFO: Refreshing
> org.springframework.context.support.ClassPathXmlApplicationContext@121cc40:
> display name
> [org.springframework.context.support.ClassPathXmlApplicationContext@121cc40];
> startup date [Thu Jul 31 02:03:35 CDT 2008]; root of context hierarchy
> Jul 31, 2008 2:03:35 AM
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader
> loadBeanDefinitions
> INFO: Loading XML bean definitions from class path resource
> [spring-config.xml]
> Jul 31, 2008 2:03:35 AM
> org.springframework.context.support.AbstractApplicationContext
> obtainFreshBeanFactory
> INFO: Bean factory for application context
> [org.springframework.context.support.ClassPathXmlApplicationContext@121cc40]:
> org.springframework.beans.factory.support.DefaultListableBeanFactory@8acf6e
> Jul 31, 2008 2:03:35 AM
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> preInstantiateSingletons
> INFO: Pre-instantiating singletons in
> org.springframework.beans.factory.support.DefaultListableBeanFactory@8acf6e:
> defining beans
> [jmsTopicConnectionFactory,TestTopic,SenderBean,MessageListener,TestJmsTopicListenerContainer,TestTopicJmsTemplate];
> root of factory hierarchy
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.BrokerService getBroker
> INFO: ActiveMQ 4.0.1 JMS Message Broker (mybrokername) is starting
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.BrokerService getBroker
> INFO: For help or more information please see:
> http://incubator.apache.org/activemq/
> Jul 31, 2008 2:03:36 AM
> org.apache.activemq.transport.TransportServerThreadSupport doStart
> INFO: Listening for connections at: tcp://dacar-collector:55707
> Jul 31, 2008 2:03:36 AM
> org.apache.activemq.transport.discovery.multicast.MulticastDiscoveryAgent
> start
> WARNING: brokerName not set
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.TransportConnector start
> INFO: Connector tcp://dacar-collector:55707 Started
> Jul 31, 2008 2:03:36 AM org.apache.activemq.network.NetworkConnector doStart
> INFO: Network Connector bridge Started
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.BrokerService start
> INFO: ActiveMQ JMS Message Broker (mybrokername,
> ID:dacar-collector-35217-1217487816143-1:0) started
> Jul 31, 2008 2:03:36 AM org.apache.activemq.transport.vm.VMTransportFactory
> bind
> INFO: binding to broker: mybrokername
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.TransportConnector start
> INFO: Connector vm://mybrokername Started
> Jul 31, 2008 2:03:36 AM org.apache.activemq.broker.jmx.ManagementContext$1
> run
> INFO: JMX consoles can connect to
> service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
> Executing in SENDER mode...
>   
> Sending message 0[New message at Thu Jul 31 02:03:36 CDT 2008 from thread
> com.ssi.exp.TestMessageSender@7eb6e2]
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Received message # 0
> Received [ActiveMQObjectMessage {commandId = 0, responseRequired = false,
> messageId = null, originalDestination = null, originalTransactionId = null,
> producerId = null, destination = null, transactionId = null, expiration = 0,
> timestamp = 0, arrival = 0, correlationId = null, replyTo = null, persistent
> = false, type = null, priority = 0, groupID = null, groupSequence = 0,
> targetConsumerId = null, compressed = false, userID = null, content = null,
> marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
> size = 0, properties = null, readOnlyProperties = false, readOnlyBody =
> false}] at Thu Jul 31 02:03:36 CDT 2008 in listener
> com.ssi.exp.TestMessageListener@8aeb74
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>   
>
>   
> Sending message 1[New message at Thu Jul 31 02:03:39 CDT 2008 from thread
> com.ssi.exp.TestMessageSender@7eb6e2]
>   
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Received message # 1
> Received [ActiveMQObjectMessage {commandId = 0, responseRequired = false,
> messageId = null, originalDestination = null, originalTransactionId = null,
> producerId = null, destination = null, transactionId = null, expiration = 0,
> timestamp = 0, arrival = 0, correlationId = null, replyTo = null, persistent
> = false, type = null, priority = 0, groupID = null, groupSequence = 0,
> targetConsumerId = null, compressed = false, userID = null, content = null,
> marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
> size = 0, properties = null, readOnlyProperties = false, readOnlyBody =
> false}] at Thu Jul 31 02:03:39 CDT 2008 in listener
> com.ssi.exp.TestMessageListener@8aeb74
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>   
> Sending message 2[New message at Thu Jul 31 02:03:42 CDT 2008 from thread
> com.ssi.exp.TestMessageSender@7eb6e2]
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Received message # 2
> Received [ActiveMQObjectMessage {commandId = 0, responseRequired = false,
> messageId = null, originalDestination = null, originalTransactionId = null,
> producerId = null, destination = null, transactionId = null, expiration = 0,
> timestamp = 0, arrival = 0, correlationId = null, replyTo = null, persistent
> = false, type = null, priority = 0, groupID = null, groupSequence = 0,
> targetConsumerId = null, compressed = false, userID = null, content = null,
> marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
> size = 0, properties = null, readOnlyProperties = false, readOnlyBody =
> false}] at Thu Jul 31 02:03:42 CDT 2008 in listener
> com.ssi.exp.TestMessageListener@8aeb74
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>   
>
>   
> Sending message 3[New message at Thu Jul 31 02:03:45 CDT 2008 from thread
> com.ssi.exp.TestMessageSender@7eb6e2]
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Received message # 3
> Received [ActiveMQObjectMessage {commandId = 0, responseRequired = false,
> messageId = null, originalDestination = null, originalTransactionId = null,
> producerId = null, destination = null, transactionId = null, expiration = 0,
> timestamp = 0, arrival = 0, correlationId = null, replyTo = null, persistent
> = false, type = null, priority = 0, groupID = null, groupSequence = 0,
> targetConsumerId = null, compressed = false, userID = null, content = null,
> marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
> size = 0, properties = null, readOnlyProperties = false, readOnlyBody =
> false}] at Thu Jul 31 02:03:45 CDT 2008 in listener
> com.ssi.exp.TestMessageListener@8aeb74
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>   
>
>   
> Sending message 4[New message at Thu Jul 31 02:03:48 CDT 2008 from thread
> com.ssi.exp.TestMessageSender@7eb6e2]
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Received message # 4
> Received [ActiveMQObjectMessage {commandId = 0, responseRequired = false,
> messageId = null, originalDestination = null, originalTransactionId = null,
> producerId = null, destination = null, transactionId = null, expiration = 0,
> timestamp = 0, arrival = 0, correlationId = null, replyTo = null, persistent
> = false, type = null, priority = 0, groupID = null, groupSequence = 0,
> targetConsumerId = null, compressed = false, userID = null, content = null,
> marshalledProperties = null, dataStructure = null, redeliveryCounter = 0,
> size = 0, properties = null, readOnlyProperties = false, readOnlyBody =
> false}] at Thu Jul 31 02:03:48 CDT 2008 in listener
> com.ssi.exp.TestMessageListener@8aeb74
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>   
>
>
> 				
>   



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message