Announcement Announcement Module
Collapse
No announcement yet.
Connect to Jboss Topic(Jboss messaging 1.4 ) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connect to Jboss Topic(Jboss messaging 1.4 )

    Hi,
    I am working on Spring3.1 on standalone env.

    I am trying to consume messages remotely from a jboss4 machine(having Jboss messaging 1.4 as a the jms provider)

    After searching in the net I am kind of lost.

    what I have done so far is to config my applicationContext with this:


    Code:
    <bean id="tgwTopic" class="org.springframework.jndi.JndiObjectFactoryBean"
    		depends-on="jmsServerManagerImpl">
    		<property name="jndiName" value="/topic/feedTopicRealTime" />
    		<property name="jndiEnvironment">
    
    			<props>
    				<prop key="java.naming.provider.url">remove.server.url:1099</prop>
    				<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
    				<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
    				<!-- other key=values here -->
    			</props>
    		</property>
    	</bean>
    and this is my java bean:

    Code:
    @Service("TGWMDB")
    public class TGWMDB implements MessageListener
    {
           @Autowired	Topic tgwTopic;
    
    
    
          public void onMessage(Message message)
          {
          }
    
    }
    {

    How should I continue my configuration in the applicationContext and in the java code.

    thanks,
    ray.

  • #2
    I suggest you read the reference guide especially the JMS section. Judging by your questions you are trying to get JMS working but without reading the manual ...

    You want to use a MessageListenerContainer instead of messing around with topics and listeners yourself.

    Comment


    • #3
      Hi Marten,

      I have listened to your advice and I went to read the manual about this for couple of hours now.

      I also implemented it as you suggested with MessageListenerContainer.

      Everything seems to be configured fine(no errors) just that I dont recieve any messages.

      I know for sure messages being sent to this topic but my java listener code never gets any.

      (please ignore the hornetQ Queue configuration. I haven't delete it from the xml since mybe that could be the reason I dont receive messages)


      here is my code:

      applicationXml:

      (The remote listening configuration starting from this line

      <!--Starting configuration with remote topic in jboss from here! -->)

      Code:
      <?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:p="http://www.springframework.org/schema/p"
      	xmlns:aop="http://www.springframework.org/schema/aop" 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-3.0.xsd
      	http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">
      
      	<context:annotation-config />
      
      	<context:component-scan base-package="com.fixgw">
      	</context:component-scan>
      
      	<bean id="TriggerBean" class="com.fixgw.test.TriggerBean">
      	</bean>
      
      	<bean id="registry" class="java.rmi.registry.LocateRegistry"
      		factory-method="createRegistry">
      		<constructor-arg value="10099" />
      	</bean>
      
      	<bean class="org.springframework.jmx.support.ConnectorServerFactoryBean"
      		depends-on="rmiRegistry">
      		<property name="objectName" value="connector:name=rmi" />
      		<property name="serviceUrl"
      			value="service:jmx:rmi://localhost/jndi/rmi://localhost:10099/jmxrmi" />
      	</bean>
      
      	<bean id="rmiRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
      		<property name="port" value="10099" />
      	</bean>
      
      
      	<bean name="namingServerImpl" class="org.jnp.server.NamingBeanImpl"
      		init-method="start" destroy-method="stop" />
      
      	<bean name="namingServer" class="org.jnp.server.Main" init-method="start"
      		destroy-method="stop">
      		<property name="namingInfo" ref="namingServerImpl" />
      		<property name="port" value="1099" />
      		<property name="bindAddress" value="localhost" />
      		<property name="rmiPort" value="3000" />
      		<property name="rmiBindAddress" value="localhost" />
      	</bean>
      
      	<bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration"
      		init-method="start" destroy-method="stop" />
      
      	<bean name="hornetQSecurityManagerImpl"
      		class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl" />
      
      	<!-- The core server -->
      	<bean name="hornetQServerImpl" class="org.hornetq.core.server.impl.HornetQServerImpl">
      		<constructor-arg ref="fileConfiguration" />
      		<constructor-arg ref="mbeanServer" />
      		<constructor-arg ref="hornetQSecurityManagerImpl" />
      	</bean>
      
      	<!-- The JMS server -->
      	<bean name="jmsServerManagerImpl" class="org.hornetq.jms.server.impl.JMSServerManagerImpl"
      		init-method="start" destroy-method="stop" depends-on="namingServer">
      		<constructor-arg ref="hornetQServerImpl" />
      	</bean>
      
      	<bean name="connectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
      		<constructor-arg name="ha" value="false" />
      		<constructor-arg>
      			<bean class="org.hornetq.api.core.TransportConfiguration">
      				<constructor-arg
      					value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
      				<constructor-arg>
      					<map key-type="java.lang.String" value-type="java.lang.Object">
      						<entry key="port" value="5445"></entry>
      					</map>
      				</constructor-arg>
      			</bean>
      		</constructor-arg>
      	</bean>
      
      	<bean id="notificationsQueue" class="org.springframework.jndi.JndiObjectFactoryBean"
      		depends-on="jmsServerManagerImpl">
      		<property name="jndiName">
      			<value>/queue/Notifications</value>
      		</property>
      	</bean>
      
      	<bean id="inVMConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
      		depends-on="jmsServerManagerImpl">
      		<property name="jndiName">
      			<value>java:/ConnectionFactory</value>
      		</property>
      	</bean>
      
         <!--Starting configuration with remote topic in jboss from here! -->
      
      
      	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
      		<property name="environment">
      			<props>
      				<prop key="java.naming.provider.url">jnp://jboss.on.remote.machine.ip:1099</prop>
      				<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
      				<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
      			</props>
      		</property>
      	</bean>
      
      
      
      	<bean id="jndiTopicConnFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
      		<property name="jndiTemplate" ref="jndiTemplate" />
      		<!-- JNDI name of connection factory as defined by provider -->
      		<property name="jndiName" value="ConnectionFactory" />
      	</bean>
      
      	<bean id="topicConnFactory"
      		class="org.springframework.jms.connection.CachingConnectionFactory">
      		<property name="targetConnectionFactory" ref="jndiTopicConnFactory" />
      		<!-- Number of sessions that will be cached -->
      		<property name="sessionCacheSize" value="1" />
      	</bean>
      
      
      	<bean id="destinationResolver"
      		class="org.springframework.jms.support.destination.JndiDestinationResolver">
      		<property name="jndiTemplate" ref="jndiTemplate" />
      		<property name="cache" value="true" />
      		<!--
      			do not create a dynamic destination if the destination name is not
      			found in JNDI
      		-->
      		<property name="fallbackToDynamicDestination" value="false" />
      	</bean>
      
      	<bean id="TgwMDB" class="com.fixgw.mdb.TgwMDB" />
      
      	<bean id="jmsContainer"
      		class="org.springframework.jms.listener.DefaultMessageListenerContainer">
      		<property name="connectionFactory" ref="topicConnFactory" />
      		<property name="pubSubDomain" value="true" />
      		<property name="destinationResolver" ref="destinationResolver" />
      		<property name="concurrentConsumers" value="1" />
      		<property name="destinationName" value="/topic/feedTopicRealTime" />
      		<property name="messageListener" ref="TgwMDB" />
      		<property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
      	</bean>
      
      
      	<!--
      
      		<jms:listener-container connection-factory="topicConnFactory"
      		destination-resolver="destinationResolver" cache="none"
      		destination-type="topic"> <jms:listener
      		destination="topic/feedTopicRealTime" ref="TgwMDB" />
      		</jms:listener-container>
      	-->
      
      
      </beans>
      and this is my java code:

      Code:
      package com.fixgw.mdb;
      
      public class TgwMDB implements MessageListener
      {
      
      	@Override
      	public void onMessage(Message message)
      	{
      		System.out.println("1");
      		if (message instanceof TextMessage)
      		{
      			try
      			{
      				String text = ((TextMessage) message).getText();
      				System.out.println("The Notification Messageeee is : \n" + text);
      			}
      			catch (JMSException ex)
      			{
      				throw new RuntimeException(ex);
      			}
      		}
      		else
      		{
      			throw new IllegalArgumentException("Message must be of type TextMessage");
      		}
      	}
      }

      I never get to print "1".


      this is my trace log:


      2012-07-04 16:41:26,028 org.springframework.jms.connection.CachingConnecti onFactory [INFO] Established shared JMS Connection: JBossConnection->ConnectionDelegate[9608099, ID=yyhq-q7pgg84h-1-uokk884h-tm7hlp-u2k5o4c5, SID=11]
      2012-07-04 16:41:26,043 org.springframework.jms.listener.DefaultMessageLis tenerContainer [DEBUG] Established shared JMS Connection
      2012-07-04 16:41:26,043 org.springframework.jms.listener.DefaultMessageLis tenerContainer [DEBUG] Resumed paused task: org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker@c7cadf
      2012-07-04 16:41:26,043 org.springframework.context.support.DefaultLifecyc leProcessor [DEBUG] Successfully started bean 'jmsContainer'
      2012-07-04 16:41:26,043 org.springframework.beans.factory.support.DefaultL istableBeanFactory [DEBUG] Returning cached instance of singleton bean 'TriggerBean'

      2012-07-04 16:41:26,153 org.springframework.jms.connection.CachingConnecti onFactory [DEBUG] Creating cached JMS Session for mode 1: JBossSession->SessionDelegate[18186103, ID=zyhq-7apgg84h-1-uokk884h-tm7hlp-u2k5o4c5]
      2012-07-04 16:41:26,168 org.springframework.jndi.JndiTemplate [DEBUG] Looking up JNDI object with name [/topic/feedTopicRealTime]
      2012-07-04 16:41:26,168 org.springframework.jms.support.destination.JndiDe stinationResolver [DEBUG] Located object with JNDI name [/topic/feedTopicRealTime]
      2012-07-04 16:41:26,199 org.springframework.jms.connection.CachingConnecti onFactory [DEBUG] Creating cached JMS MessageConsumer for destination [JBossTopic[feedTopicRealTime]]: JBossMessageConsumer->ConsumerDelegate[7299176, ID=0zhq-zdpgg84h-1-uokk884h-tm7hlp-u2k5o4c5]
      [/CODE]


      No errors indeed.

      thanks a lot,
      ray.

      Comment


      • #4
        Okie.. I did had problem with the Topic url.

        anyway it work fine

        good example for anyone who trying to do this.

        in the end ill master that!!:P thanks.

        Comment


        • #5
          HI,

          What I would try to understand is the DestinationResolver bean purpose. I tried to read about it from the documents but I didnt get it.

          what it suppose to do?

          Code:
          <bean id="destinationResolver"
          		class="org.springframework.jms.support.destination.JndiDestinationResolver">
          		<property name="jndiTemplate" ref="jndiTemplate" />
          		<property name="cache" value="true" />
          		<!--
          			do not create a dynamic destination if the destination name is not
          			found in JNDI
          		-->
          		<property name="fallbackToDynamicDestination" value="false" />
          	</bean>
          thanks,
          ray.

          Comment

          Working...
          X