I have set up a small example of a sender and a receiver in two
different servicemix containers using a jms flow.
When I run the two on the same machine the sender can communicate with
the receiver. But when I run them on two different machines in the same
subnet I get an error message:
01:46:04,578 WARN [NetworkConnector] Could not start network bridge
between: vm://peer-wschris-2808-1163292341312-0-0?network=true and:
tcp://notebook:1849 due to: java.net.ConnectException: Connection timed
out: connect
01:46:04,578 DEBUG [NetworkConnector] Start failure exception:
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
Any idea what I am doing wrong?
Many thanks in advance
Christian
Attached you will find the code for my sender and receiver:
---
The sender testcase. It sends an InOnly and an InOut message. In the
case of the InOut message it prints the out message
import java.util.EventListener;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOut;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.view.DotViewEndpointListener;
import org.apache.servicemix.jbi.view.DotViewFlowListener;
public class ClusterSender extends TestCase {
private static Log logger = LogFactory.getLog(ClusterSender.class);
protected JBIContainer container;
protected void setUp() throws Exception {
BasicConfigurator.configure(new ConsoleAppender());
Logger.getRootLogger().setLevel(Level.DEBUG);
container = new JBIContainer();
container.setName("SenderContainer");
container.setUseMBeanServer(false);
container.setCreateMBeanServer(false);
container.setMonitorInstallationDirectory(false);
container.setNamingContext(new InitialContext());
container.setEmbedded(true);
container.setFlowName("jms");
container.setListeners(new EventListener[]{new
DotViewFlowListener(), new DotViewEndpointListener()});
container.init();
}
protected void tearDown() throws Exception {
if (container != null) {
container.shutDown();
}
}
public void testSend() throws Exception {
container.start();
QName receiverService = new QName("http://my", "Receiver");
ServiceMixClient client = new DefaultServiceMixClient(container);
InOnly me = client.createInOnlyExchange();
//me.setInterfaceName(receiverService);
me.setService(receiverService);
me.getInMessage().setContent(new StringSource("<oneWay
xmlns='http://jsr181.servicemix.apache.org'><in0>world</in0></oneWay>"));
client.sendSync(me);
InOut me2 = client.createInOutExchange();
me2.setService(receiverService);
me2.getInMessage().setContent(new StringSource("<oneWay
xmlns='http://jsr181.servicemix.apache.org'><in0>world</in0></oneWay>"));
client.sendSync(me2);
SourceTransformer transformer = new SourceTransformer();
String st = transformer.toString(me2.getOutMessage().getContent());
System.out.println(st);
}
}
---
The receiver testcase. It activates the receiver component and waits
import java.util.EventListener;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.servicemix.jbi.container.ActivationSpec;
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.view.DotViewEndpointListener;
import org.apache.servicemix.jbi.view.DotViewFlowListener;
public class ClusterReceiver extends TestCase {
private static Log logger = LogFactory.getLog(ClusterReceiver.class);
protected JBIContainer container;
protected void setUp() throws Exception {
BasicConfigurator.configure(new ConsoleAppender());
Logger.getRootLogger().setLevel(Level.DEBUG);
logger.info("Start");
System.out.println("start");
container = new JBIContainer();
container.setName("ReceiverContainer");
container.setUseMBeanServer(false);
container.setCreateMBeanServer(false);
container.setMonitorInstallationDirectory(false);
container.setNamingContext(new InitialContext());
container.setEmbedded(true);
container.setFlowName("jms");
container.setRmiPort(1001);
container.setListeners(new EventListener[]{new
DotViewFlowListener(), new DotViewEndpointListener()});
container.init();
}
protected void tearDown() throws Exception {
if (container != null) {
container.shutDown();
}
}
public void testSend() throws Exception {
container.start();
QName receiverService = new QName("http://my", "Receiver");
Receiver receiver = new Receiver();
receiver.setService(receiverService);
ActivationSpec spec = new ActivationSpec(receiver);
//spec.setInterfaceName(receiverService);
spec.setService(receiverService);
container.activateComponent(spec);
System.in.read();
}
}
---
The receiver component
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import org.apache.servicemix.components.util.OutBinding;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
public class Receiver extends OutBinding {
@Override
protected void process(MessageExchange messageExchange,
NormalizedMessage message) throws Exception {
SourceTransformer transformer = new SourceTransformer();
System.out.println(transformer.toString(message.getContent()));
System.out.println(messageExchange);
NormalizedMessage out = new NormalizedMessageImpl();
try {
out.setContent(new StringSource("<oneWay
xmlns='http://jsr181.servicemix.apache.org'><in0>Processed</in0></oneWay>"));
messageExchange.setMessage(out, "out");
} catch (Exception e) {
e.printStackTrace();
}
done(messageExchange);
}
}
---
Here is the full log for the sender in debug level:
01:45:40,312 INFO [JBIContainer] ServiceMix 3.0.1-incubating JBI
Container (SenderContainer) is starting
01:45:40,312 INFO [JBIContainer] For help or more informations please
see: http://incubator.apache.org/servicemix/
log4j:ERROR No output stream or file set for the appender named [null].
01:45:40,703 DEBUG [JmxUtils] Found MBeanServer:
[EMAIL PROTECTED]
01:45:40,890 INFO [ConnectorServerFactoryBean] JMX connector server
started: [EMAIL PROTECTED]
01:45:40,890 INFO [ConnectorServerFactoryBean] JMX connector available
at: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
01:45:40,984 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=ManagementContext
01:45:40,984 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=EnvironmentContext
01:45:40,984 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=ClientFactory
01:45:41,000 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=Registry
01:45:41,000 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=DefaultBroker
01:45:41,062 DEBUG [JMSFlow] SenderContainer: Initializing jms flow
01:45:41,515 INFO [BrokerService] ActiveMQ 4.0.2 JMS Message Broker
(peer-wschris-2808-1163292341312-0-0) is starting
01:45:41,515 INFO [BrokerService] For help or more information please
see: http://incubator.apache.org/activemq/
01:45:41,875 INFO [TransportServerThreadSupport] Listening for
connections at: tcp://wschris:2809
01:45:41,875 WARN [MulticastDiscoveryAgent] brokerName not set
01:45:41,968 INFO [TransportConnector] Connector tcp://wschris:2809 Started
01:45:42,218 INFO [NetworkConnector] Network Connector bridge Started
01:45:42,218 INFO [BrokerService] ActiveMQ JMS Message Broker
(peer-wschris-2808-1163292341312-0-0, ID:wschris-2808-1163292341312-1:0)
started
01:45:42,218 DEBUG [VMTransportFactory] binding to broker:
peer-wschris-2808-1163292341312-0-0
01:45:42,390 DEBUG [WireFormatNegotiator] Sending: WireFormatInfo {
version=1, properties={TightEncodingEnabled=true,
TcpNoDelayEnabled=true, SizePrefixDisabled=false,
StackTraceEnabled=true, MaxInactivityDuration=30000, CacheEnabled=true},
magic=[A,c,t,i,v,e,M,Q]}
01:45:42,390 DEBUG [TcpTransport] TCP consumer thread starting
01:45:42,437 INFO [TransportConnector] Connector
vm://peer-wschris-2808-1163292341312-0-0 Started
01:45:42,578 DEBUG [WireFormatNegotiator] Received WireFormat:
WireFormatInfo { version=1, properties={StackTraceEnabled=true,
TightEncodingEnabled=true, TcpNoDelayEnabled=true,
SizePrefixDisabled=false, MaxInactivityDuration=30000,
CacheEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
01:45:42,578 DEBUG [WireFormatNegotiator] tcp:///10.0.0.100:1976 before
negotiation: OpenWireFormat{version=1, cacheEnabled=false,
stackTraceEnabled=false, tightEncodingEnabled=false,
sizePrefixDisabled=false}
01:45:42,593 DEBUG [WireFormatNegotiator] tcp:///10.0.0.100:1976 after
negotiation: OpenWireFormat{version=1, cacheEnabled=true,
stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false}
01:45:42,640 INFO [NetworkConnector] Establishing network connection
between from vm://peer-wschris-2808-1163292341312-0-0?network=true to
tcp://notebook:1849
01:45:42,750 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Connection
01:45:42,812 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Topic
01:45:43,109 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Consumer.Queue.org.apache.servicemix.jms.SenderContainer
01:45:43,140 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Producer.Topic.org.apache.servicemix.JMSFlow
01:45:43,343 INFO [JBIContainer] Activating component for:
[container=SenderContainer,name=#SubscriptionManager#] with service:
null component: [EMAIL PROTECTED]
01:45:43,500 INFO [ComponentMBeanImpl] Initializing component:
#SubscriptionManager#
01:45:43,531 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=InstallationService
01:45:43,531 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=DeploymentService
01:45:43,531 INFO [DeploymentService] Restoring service assemblies
01:45:43,531 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=AutoDeploymentService
01:45:43,546 DEBUG [ManagementContext] Registering system service:
org.apache.servicemix:ContainerName=SenderContainer,Type=SystemService,Name=AdminCommandsService
01:45:43,546 WARN [ClientFactory] Cound not start ClientFactory:
javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
01:45:43,546 DEBUG [ClientFactory] Could not start ClientFactory
javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.bind(InitialContext.java:359)
at
org.apache.servicemix.jbi.framework.ClientFactory.start(ClientFactory.java:82)
at
org.apache.servicemix.jbi.container.JBIContainer.start(JBIContainer.java:591)
at ClusterSender.testOrder(ClusterSender.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
01:45:43,593 DEBUG [JMSFlow] SenderContainer: Starting jms flow
01:45:43,593 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Consumer.Topic.org.apache.servicemix.JMSFlow
01:45:43,625 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Consumer.Queue.org.apache.servicemix.jms.#SubscriptionManager#
01:45:43,656 INFO [JBIContainer] ServiceMix JBI Container
(SenderContainer) started
01:45:43,687 INFO [JBIContainer] Activating component for:
[container=SenderContainer,name=ID:wschris-2803-1163292339953-0:0] with
service: null component:
[EMAIL PROTECTED]
01:45:43,687 INFO [ComponentMBeanImpl] Initializing component:
ID:wschris-2803-1163292339953-0:0
01:45:43,687 INFO [ComponentMBeanImpl] Starting component:
ID:wschris-2803-1163292339953-0:0
01:45:43,687 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Consumer.Queue.org.apache.servicemix.jms.ID:wschris-2803-1163292339953-0:0
01:45:43,703 DEBUG [AbstractRegion] Adding destination:
topic://org.apache.servicemix.JMSFlow
01:45:43,750 DEBUG [JMSFlow] SenderContainer: adding remote endpoint:
ServiceEndpoint[service={http://my}Receiver,endpoint=ID:notebook-1843-1163288108953-0:0]
01:45:43,750 DEBUG [DotViewEndpointListener] Creating DOT file at:
ServiceMixComponents.dot
01:45:43,781 DEBUG [DotViewEndpointListener] Creating DOT file at:
ServiceMixFlow.dot
01:45:43,937 DEBUG [DeliveryChannelImpl] SendSync
ID:wschris-2808-1163292341312-8:0 in
DeliveryChannel{ID:wschris-2803-1163292339953-0:0}
01:45:44,796 DEBUG [DeliveryChannelImpl] Sent: InOnly[
id: ID:wschris-2808-1163292341312-8:0
status: Active
role: consumer
service: {http://my}Receiver
in: <?xml version="1.0" encoding="UTF-8"?><oneWay
xmlns="http://jsr181.servicemix.apache.org"><in0>world</in0></oneWay>
]
01:45:44,796 DEBUG [DefaultBroker] Routing exchange InOnly[
id: ID:wschris-2808-1163292341312-8:0
status: Active
role: provider
service: {http://my}Receiver
endpoint: ID:notebook-1843-1163288108953-0:0
in: <?xml version="1.0" encoding="UTF-8"?><oneWay
xmlns="http://jsr181.servicemix.apache.org"><in0>world</in0></oneWay>
] to:
ServiceEndpoint[service={http://my}Receiver,endpoint=ID:notebook-1843-1163288108953-0:0]
01:45:44,796 DEBUG [JMSFlow] Called Flow send
01:45:44,890 DEBUG [ActiveMQSession] Sending message:
ActiveMQObjectMessage {commandId = 0, responseRequired = false,
messageId = ID:wschris-2808-1163292341312-4:0:1:1:1, originalDestination
= null, originalTransactionId = null, producerId =
ID:wschris-2808-1163292341312-4:0:1:1, destination =
queue://org.apache.servicemix.jms.{http://my}Receiver:ID:notebook-1843-1163288108953-0:0,
transactionId = null, expiration = 0, timestamp = 1163292344875, arrival
= 0, correlationId = null, replyTo = null, persistent = true, type =
null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId
= null, compressed = false, userID = null, content =
[EMAIL PROTECTED], marshalledProperties =
null, dataStructure = null, redeliveryCounter = 0, size = 0, properties
= null, readOnlyProperties = true, readOnlyBody = true}
01:45:44,890 DEBUG [AbstractRegion] Adding destination:
queue://org.apache.servicemix.jms.{http://my}Receiver:ID:notebook-1843-1163288108953-0:0
01:45:44,906 DEBUG [AbstractRegion] Adding destination:
topic://ActiveMQ.Advisory.Queue
01:45:44,937 DEBUG
[{http://my}Receiver:ID:notebook-1843-1163288108953-0:0] No
subscriptions registered, will not dispatch message at this time.
01:45:44,937 DEBUG [DeliveryChannelImpl] Waiting for exchange
ID:wschris-2808-1163292341312-8:0 (67ec28) to be answered in
DeliveryChannel{ID:wschris-2803-1163292339953-0:0} from sendSync
01:45:57,453 DEBUG [InactivityMonitor] Message sent since last write
check, resetting flag
01:46:04,578 WARN [NetworkConnector] Could not start network bridge
between: vm://peer-wschris-2808-1163292341312-0-0?network=true and:
tcp://notebook:1849 due to: java.net.ConnectException: Connection timed
out: connect
01:46:04,578 DEBUG [NetworkConnector] Start failure exception:
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:516)
at
org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:272)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:48)
at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:52)
at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:52)
at
org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:59)
at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:52)
at
org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:52)
at
org.apache.activemq.network.DemandForwardingBridgeSupport.start(DemandForwardingBridgeSupport.java:176)
at
org.apache.activemq.network.DiscoveryNetworkConnector.onServiceAdd(DiscoveryNetworkConnector.java:121)
at
org.apache.activemq.transport.discovery.multicast.MulticastDiscoveryAgent$2.run(MulticastDiscoveryAgent.java:341)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
01:46:04,578 DEBUG [DemandForwardingBridge] stopping
peer-wschris-2808-1163292341312-0-0 bridge to Unknown is disposed
already ? false
01:46:04,609 DEBUG [DemandForwardingBridge] Caught exception stopping
java.io.IOException: Transport disposed.
at
org.apache.activemq.transport.vm.VMTransport.oneway(VMTransport.java:69)
at
org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:44)
at
org.apache.activemq.transport.ResponseCorrelator.oneway(ResponseCorrelator.java:58)
at
org.apache.activemq.network.DemandForwardingBridgeSupport.stop(DemandForwardingBridgeSupport.java:291)
at
org.apache.activemq.util.ServiceSupport.dispose(ServiceSupport.java:39)
at
org.apache.activemq.network.DiscoveryNetworkConnector.onServiceRemove(DiscoveryNetworkConnector.java:154)
at
org.apache.activemq.transport.discovery.multicast.MulticastDiscoveryAgent$3.run(MulticastDiscoveryAgent.java:370)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
01:46:04,609 DEBUG [DemandForwardingBridge]
peer-wschris-2808-1163292341312-0-0 bridge to Unknown stopped
--
Christian Schneider
---
http://www.liquid-reality.de