You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by archana saini <ar...@gmail.com> on 2011/01/23 15:10:03 UTC

Not able to start connection with ActiveMQ broker from a network client.

Hi All,

I am new to ActiveMQ. I have to write a consumer for activeMQ queue.
ActiveMQ brokers already setup by other team. 

When i am trying to connect to broker using tcp it stuck at line
connection.start().
Java control doesnt go beyond this line. I never recieved an
exception/error.. it seems its waiting for connection. 

Belwo is teh simple code i am using. As i havent setup ActiveMQ, i am just
trying to recieve messge from a queue. I do not have setup info of activeMQ,
is there some setting required at ActiveMQ setup end. 

Note:- ActiveMq setup are on different server i am runnning cosumer on my
local. So it is connection over teh network.

Code:-

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;
public class ActiveMQTest {
	
	    private static String brokerURL =
"failover://(tcp://rpc1044.daytonoh.ncr.com:61616?trace=true)";
	    private static transient ConnectionFactory factory;
	    private transient Connection connection;
	    private transient Session session;
	    
	    private String jobs[] = new String[]{"suspend", "delete"};
	    
	    public ActiveMQTest() throws JMSException {
	    	factory = new ActiveMQConnectionFactory(brokerURL);
	    	System.out.println("------");
	    	connection = factory.createConnection();
	        
	    	System.out.println("1");
	    	connection.start();
	    	System.out.println("2");
	        session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
	    }
	    
	    public void close() throws JMSException {
	        if (connection != null) {
	            connection.close();
	        }
	    }    
	    
	    public static void main(String[] args) throws JMSException {
	    	ActiveMQTest consumer = new ActiveMQTest();
	    	for (String job : consumer.jobs) {
	    		Destination destination = consumer.getSession().createQueue("JOBS." +
job);
	    		MessageConsumer messageConsumer =
consumer.getSession().createConsumer(destination);
	    		messageConsumer.setMessageListener(new Listener(job));
	    	}
	    }
		
		public Session getSession() {
			return session;
		}


	}




import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

public class Listener implements MessageListener {

	private String job;
	
	public Listener(String job) {
		this.job = job;
	}

	public void onMessage(Message message) {
		try {
			//do something here
			System.out.println(job + " id:" + ((ObjectMessage)message).getObject());
			Thread.sleep(1000);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}


It never prints "2" in logs. it stuck at line connection.start(). 

Any help would be appreciated. Thanks!


Reagrds
Archana
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3232550.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by LeonelDuran <le...@hotmail.com>.
Thanks Tim. 

you know Why does this happen?, the error occurs in a single cluster node
and the configurtion was the same.... please help me 



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-Dev-f2368404.html

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by archana saini <ar...@gmail.com>.
Thanks Tim. It worked for me.

Thanks for your help!

Regards
Archana
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3251060.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by Timothy Bish <ta...@gmail.com>.
On Sun, 2011-01-23 at 08:48 -0800, archana saini wrote:
> Here is the content of activemq.xml
> 
> <!-- START SNIPPET: example -->
> <beans
>   xmlns="http://www.springframework.org/schema/beans"
>   xmlns:amq="http://activemq.apache.org/schema/core"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>   http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd">  
>   
>     <!-- Allows us to use system properties as variables in this
> configuration file -->
>     <bean
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>         <property name="locations">
>             <value>file:${activemq.base}/conf/credentials.properties</value>
>         </property>      
>     </bean>
> 
>     <broker xmlns="http://activemq.apache.org/schema/core"
> brokerName="localhost" dataDirectory="${activemq.base}/data"
> destroyApplicationContextOnStop="true">
> 
>         <!-- Destination specific policies using destination names or
> wildcards -->
>         <destinationPolicy>
>             <policyMap>
>                 <policyEntries>
>                     <policyEntry queue=">" producerFlowControl="false"
> memoryLimit="20mb"/>
>                     <policyEntry topic=">" producerFlowControl="false"
> memoryLimit="20mb">
>                         <dispatchPolicy>
>                             <strictOrderDispatchPolicy/>
>                         </dispatchPolicy>
>                         <subscriptionRecoveryPolicy>
>                             <lastImageSubscriptionRecoveryPolicy/>
>                         </subscriptionRecoveryPolicy>
>                     </policyEntry>
>                 </policyEntries>
>             </policyMap>
>         </destinationPolicy>
> 
>         <!-- Use the following to configure how ActiveMQ is exposed in JMX
> -->
>         <managementContext>
>             <managementContext createConnector="false"/>
>         </managementContext>
> 
>         <!-- The store and forward broker networks ActiveMQ will listen to
> -->
>         <networkConnectors>
>             <!-- by default just auto discover the other brokers -->
>             <!--<networkConnector name="default-nc"
> uri="multicast://default"/>-->
>             <!-- Example of a static configuration:
>             <networkConnector name="host1 and host2"
> uri="static://(tcp://host1:61616,tcp://host2:61616)"/>
>             -->
>         </networkConnectors>
> 
>         <persistenceAdapter>
>             <journaledJDBC journalLogFiles="5"
> dataDirectory="${activemq.base}/activemq-data" dataSource="#mysql-ds"/>
>         </persistenceAdapter>
> 
>         <!-- The transport connectors ActiveMQ will listen to -->
>         <transportConnectors>
>             <transportConnector name="openwire"
> uri="tcp://localhost:61616?trace=true" discoveryUri="multicast://default"/>
>             <transportConnector name="http"
> uri="http://localhost:8090?trace=true"/>
>             <!--<transportConnector name="ssl"
> uri="ssl://localhost:61617"/>-->
>             <!--<transportConnector name="stomp"
> uri="stomp://localhost:61613"/>-->
>             <!--<transportConnector name="xmpp"
> uri="xmpp://localhost:61222"/>-->
>         </transportConnectors>
> 
>     </broker>
> 
> 	<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"
> destroy-method="close">
> 		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
> 		<property name="url"
> value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
> 		<property name="username" value="predserv"/>
> 		<property name="password" value="predserv"/>
> 		<property name="poolPreparedStatements" value="true"/>
> 	</bean>
> 
>     <!-- An embedded servlet engine for serving up the Admin console -->
>     <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
>         <connectors>
>             <nioConnector port="8161"/>
>         </connectors>
> 
>         <handlers>
>             <webAppContext contextPath="/admin"
> resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
>             <webAppContext contextPath="/demo"
> resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
>             <webAppContext contextPath="/fileserver"
> resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
>         </handlers>
>     </jetty>
> 
> 
> 
> </beans>
> <!-- END SNIPPET: example -->
> 
> 
> Thanks
> Archana

Your transports are all bound to localhost so you can only connect to
them on the loopback device, bind them to 0.0.0.0 (the any device) in
order allow outside clients to connect as well as client using loopback.

	uri="tcp://0.0.0.0:61616"

Regards

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by archana saini <ar...@gmail.com>.
Here is the content of activemq.xml

<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">  
  
    <!-- Allows us to use system properties as variables in this
configuration file -->
    <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.base}/conf/credentials.properties</value>
        </property>      
    </bean>

    <broker xmlns="http://activemq.apache.org/schema/core"
brokerName="localhost" dataDirectory="${activemq.base}/data"
destroyApplicationContextOnStop="true">

        <!-- Destination specific policies using destination names or
wildcards -->
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" producerFlowControl="false"
memoryLimit="20mb"/>
                    <policyEntry topic=">" producerFlowControl="false"
memoryLimit="20mb">
                        <dispatchPolicy>
                            <strictOrderDispatchPolicy/>
                        </dispatchPolicy>
                        <subscriptionRecoveryPolicy>
                            <lastImageSubscriptionRecoveryPolicy/>
                        </subscriptionRecoveryPolicy>
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <!-- Use the following to configure how ActiveMQ is exposed in JMX
-->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!-- The store and forward broker networks ActiveMQ will listen to
-->
        <networkConnectors>
            <!-- by default just auto discover the other brokers -->
            <!--<networkConnector name="default-nc"
uri="multicast://default"/>-->
            <!-- Example of a static configuration:
            <networkConnector name="host1 and host2"
uri="static://(tcp://host1:61616,tcp://host2:61616)"/>
            -->
        </networkConnectors>

        <persistenceAdapter>
            <journaledJDBC journalLogFiles="5"
dataDirectory="${activemq.base}/activemq-data" dataSource="#mysql-ds"/>
        </persistenceAdapter>

        <!-- The transport connectors ActiveMQ will listen to -->
        <transportConnectors>
            <transportConnector name="openwire"
uri="tcp://localhost:61616?trace=true" discoveryUri="multicast://default"/>
            <transportConnector name="http"
uri="http://localhost:8090?trace=true"/>
            <!--<transportConnector name="ssl"
uri="ssl://localhost:61617"/>-->
            <!--<transportConnector name="stomp"
uri="stomp://localhost:61613"/>-->
            <!--<transportConnector name="xmpp"
uri="xmpp://localhost:61222"/>-->
        </transportConnectors>

    </broker>

	<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url"
value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
		<property name="username" value="predserv"/>
		<property name="password" value="predserv"/>
		<property name="poolPreparedStatements" value="true"/>
	</bean>

    <!-- An embedded servlet engine for serving up the Admin console -->
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161"/>
        </connectors>

        <handlers>
            <webAppContext contextPath="/admin"
resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
            <webAppContext contextPath="/demo"
resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
            <webAppContext contextPath="/fileserver"
resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
        </handlers>
    </jetty>



</beans>
<!-- END SNIPPET: example -->


Thanks
Archana
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3232703.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by Timothy Bish <ta...@gmail.com>.
On Sun, 2011-01-23 at 07:51 -0800, archana saini wrote:
> Hi Tim,
> 
> I am not sure if it is network issue, i am able to access the same server
> from my local. I can telnet and ping that server.
> 
> Any idea?
> 
> Regards
> Archana

What does you broker configuration look like (activemq.xml)?


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by archana saini <ar...@gmail.com>.
Hi Tim,

I am not sure if it is network issue, i am able to access the same server
from my local. I can telnet and ping that server.

Any idea?

Regards
Archana
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3232651.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by Timothy Bish <ta...@gmail.com>.
On Sun, 2011-01-23 at 07:38 -0800, archana saini wrote:
> Thanks for your quick reply Tim.
> 
> If i remove the failover, i get the connection refused error:-
> 
> 
> ------
> Exception in thread "main" javax.jms.JMSException: Could not connect to
> broker URL: tcp://rpc1044.daytonoh.ncr.com:61616?trace=true. Reason:
> java.net.ConnectException: Connection refused: connect
> 	at
> org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
> 	at
> org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:286)
> 	at
> org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230)
> 	at
> org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:178)
> 	at ActiveMQTest.<init>(ActiveMQTest.java:22)
> 	at ActiveMQTest.main(ActiveMQTest.java:37)
> Caused by: java.net.ConnectException: Connection refused: connect
> 	at java.net.PlainSocketImpl.socketConnect(Native Method)
> 	at java.net.PlainSocketImpl.doConnect(Unknown Source)
> 	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
> 	at java.net.PlainSocketImpl.connect(Unknown Source)
> 	at java.net.SocksSocketImpl.connect(Unknown Source)
> 	at java.net.Socket.connect(Unknown Source)
> 	at
> org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:484)
> 	at
> org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:447)
> 	at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53)
> 	at
> org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
> 	at
> org.apache.activemq.transport.InactivityMonitor.start(InactivityMonitor.java:127)
> 	at
> org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
> 	at
> org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
> 	at
> org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
> 	at
> org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
> 	at
> org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:266)
> 	... 4 more
> 
> 
> 
> Do we define the property to allow remote connection somewhere in any
> ActiveMQ configuration XML file??
> 
> 
> Thanks & Regards
> Archana

That wouldn't be something that you'd configure on the broker its most
likely a network configuration setting or firewall issue.

Regards


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by archana saini <ar...@gmail.com>.
Thanks for your quick reply Tim.

If i remove the failover, i get the connection refused error:-


------
Exception in thread "main" javax.jms.JMSException: Could not connect to
broker URL: tcp://rpc1044.daytonoh.ncr.com:61616?trace=true. Reason:
java.net.ConnectException: Connection refused: connect
	at
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
	at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:286)
	at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230)
	at
org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:178)
	at ActiveMQTest.<init>(ActiveMQTest.java:22)
	at ActiveMQTest.main(ActiveMQTest.java:37)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(Unknown Source)
	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at
org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:484)
	at
org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:447)
	at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53)
	at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
	at
org.apache.activemq.transport.InactivityMonitor.start(InactivityMonitor.java:127)
	at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
	at
org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
	at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
	at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
	at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:266)
	... 4 more



Do we define the property to allow remote connection somewhere in any
ActiveMQ configuration XML file??


Thanks & Regards
Archana
-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3232636.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Not able to start connection with ActiveMQ broker from a network client.

Posted by Timothy Bish <ta...@gmail.com>.
On Sun, 2011-01-23 at 06:10 -0800, archana saini wrote:
> Hi All,
> 
> I am new to ActiveMQ. I have to write a consumer for activeMQ queue.
> ActiveMQ brokers already setup by other team. 
> 
> When i am trying to connect to broker using tcp it stuck at line
> connection.start().
> Java control doesnt go beyond this line. I never recieved an
> exception/error.. it seems its waiting for connection. 
> 
> Belwo is teh simple code i am using. As i havent setup ActiveMQ, i am just
> trying to recieve messge from a queue. I do not have setup info of activeMQ,
> is there some setting required at ActiveMQ setup end. 
> 
> Note:- ActiveMq setup are on different server i am runnning cosumer on my
> local. So it is connection over teh network.
> 
> Code:-
> 
> import javax.jms.Connection;
> import javax.jms.ConnectionFactory;
> import javax.jms.Destination;
> import javax.jms.JMSException;
> import javax.jms.MessageConsumer;
> import javax.jms.Session;
> 
> import org.apache.activemq.ActiveMQConnectionFactory;
> public class ActiveMQTest {
> 	
> 	    private static String brokerURL =
> "failover://(tcp://rpc1044.daytonoh.ncr.com:61616?trace=true)";
> 	    private static transient ConnectionFactory factory;
> 	    private transient Connection connection;
> 	    private transient Session session;
> 	    
> 	    private String jobs[] = new String[]{"suspend", "delete"};
> 	    
> 	    public ActiveMQTest() throws JMSException {
> 	    	factory = new ActiveMQConnectionFactory(brokerURL);
> 	    	System.out.println("------");
> 	    	connection = factory.createConnection();
> 	        
> 	    	System.out.println("1");
> 	    	connection.start();
> 	    	System.out.println("2");
> 	        session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> 	    }
> 	    
> 	    public void close() throws JMSException {
> 	        if (connection != null) {
> 	            connection.close();
> 	        }
> 	    }    
> 	    
> 	    public static void main(String[] args) throws JMSException {
> 	    	ActiveMQTest consumer = new ActiveMQTest();
> 	    	for (String job : consumer.jobs) {
> 	    		Destination destination = consumer.getSession().createQueue("JOBS." +
> job);
> 	    		MessageConsumer messageConsumer =
> consumer.getSession().createConsumer(destination);
> 	    		messageConsumer.setMessageListener(new Listener(job));
> 	    	}
> 	    }
> 		
> 		public Session getSession() {
> 			return session;
> 		}
> 
> 
> 	}
> 
> 
> 
> 
> import javax.jms.Message;
> import javax.jms.MessageListener;
> import javax.jms.ObjectMessage;
> 
> public class Listener implements MessageListener {
> 
> 	private String job;
> 	
> 	public Listener(String job) {
> 		this.job = job;
> 	}
> 
> 	public void onMessage(Message message) {
> 		try {
> 			//do something here
> 			System.out.println(job + " id:" + ((ObjectMessage)message).getObject());
> 			Thread.sleep(1000);
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 	}
> 
> }
> 
> 
> It never prints "2" in logs. it stuck at line connection.start(). 
> 
> Any help would be appreciated. Thanks!
> 
> 
> Reagrds
> Archana

You are using the failover transport so this kind of behavior is
expected if the broker isn't actually running, or the machine can't make
a connection with the broker for some reason.  Try removing the failover
transport and see what kind of error you get from the connection
attempt. 

Regards


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/