title: jboss 5 to jboss 7 jms
body: <p>I am running jboss5 and jboss 7 in same machine, so I changed port nos(jboss5-4040 and jboss7-8080). I need to send a message from jboss 5 to jboss 7. I read an article, state that, have to use JMS bridge.</p>
  
  <pre><code>https://community.jboss.org/wiki/BridgeJMSMessagesFromAS5ToAS7
  </code></pre>
  
  <p>I created a queue in jboss 5 and sent messages to the queue by standalone program.</p>
  
  <pre><code>import java.io.Console;
  import java.util.Properties;
  import javax.jms.*;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  public class sender {
      String url_;
      String name_;
      Connection conn = null;
      Session session = null;
      Queue queue = null;
  
      public sender(String url, String name) throws JMSException,
              NamingException {
  
          url_ = url;
          name_ = name;
  
          this.initializeSender();
      }
  
      private void initializeSender() throws JMSException, NamingException {
  
          Properties props = new Properties();
          props.setProperty("java.naming.factory.initial",
                  "org.jnp.interfaces.NamingContextFactory");
          props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
  
          props.setProperty("java.naming.provider.url", "jnp://localhost:1099");
  
          Context context = new InitialContext(props);
  
          ConnectionFactory cf = (ConnectionFactory) context
                  .lookup("java:/ConnectionFactory");
  
          conn = cf.createConnection();
  
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  
          queue = (Queue) context.lookup(name_);
  
          conn.start();
  
      }
  
      public void send(String text) throws JMSException, NamingException {
          // Send a text msg
          MessageProducer producer = session.createProducer(queue);
          TextMessage tm = session.createTextMessage(text);
          producer.send(tm);
          producer.close();
      }
  
      public void disconnect() throws JMSException {
          if (conn != null) {
              conn.stop();
          }
  
          if (session != null) {
              session.close();
          }
  
          if (conn != null) {
              conn.close();
          }
      }
  
      public String getTopicName() {
          return name_;
      }
  
      public String getTopicURL() {
          return url_;
      }
  
      public static void main(String args[]) throws Exception {
  
          sender sender = new sender("remote://localhost:4447", "BalaQueue");
  
          sender.send("My Message");
          sender.disconnect();
  
  
      }
  
  }
  </code></pre>
  
  <p>and I created a queue in jboss 7 and sent messages to the queue by standalone program.</p>
  
  <pre><code>import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.util.Properties;
  
  import javax.jms.Queue;
  import javax.jms.QueueConnection;
  import javax.jms.QueueConnectionFactory;
  import javax.jms.QueueSender;
  import javax.jms.QueueSession;
  import javax.jms.Session;
  import javax.jms.TextMessage;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  
  public class QSender {
      public static void main(String[] args) {
          new QSender().send();
      }
  
      public void send() {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  System.in));
          try {
              // Strings for JNDI names
              String factoryName = "jms/RemoteConnectionFactory";
              String queueName = "jms/queue/ram";
              // Create an initial context.
              Properties props = new Properties();
              props.put(Context.INITIAL_CONTEXT_FACTORY,
                      "org.jboss.naming.remote.client.InitialContextFactory");
              props.put(Context.PROVIDER_URL, "remote://localhost:4447");
              props.put(Context.SECURITY_PRINCIPAL, "ramguest");
              props.put(Context.SECURITY_CREDENTIALS, "password");
              InitialContext context = new InitialContext(props);
  
              QueueConnectionFactory factory = (QueueConnectionFactory) context
                      .lookup(factoryName);
              Queue queue = (Queue) context.lookup(queueName);
              context.close();
              // Create JMS objects
              QueueConnection connection = factory.createQueueConnection(
                      "ramguest", "password");
              QueueSession session = connection.createQueueSession(false,
                      Session.AUTO_ACKNOWLEDGE);
              QueueSender sender = session.createSender(queue);
  
              System.out.println("Enter message to send or 'quit' to quit.");
              String messageText = null;
              while (true) {
                  messageText = reader.readLine();
                  if ("quit".equalsIgnoreCase(messageText)) {
                      break;
                  }
                  TextMessage message = session.createTextMessage(messageText);
                  sender.send(message);
              }
              // Exit
              reader.close();
              System.out.println("Exiting...");
              connection.close();
          } catch (Exception e) {
              e.printStackTrace();
              System.exit(1);
          }
      }
  }
  </code></pre>
  
  <p>and my bridge file(jboss-service.xml)</p>
  
  <pre><code>&lt;server&gt;    
      &lt;loader-repository&gt;com.example:archive=unique-archive-name
          &lt;loader-repository-config&gt;java2ParentDelegation=false&lt;/loader-repository-config&gt;
      &lt;/loader-repository&gt;    &lt;!-- AS7 JMS Provider --&gt;    
      &lt;mbean code="org.jboss.jms.jndi.JMSProviderLoader" name="jboss.messaging:service=JMSProviderLoader,name=RemoteJBossMQProvider"&gt;     &lt;attribute name="ProviderName"&gt;RemoteXAConnectionFactory&lt;/attribute&gt;       
          &lt;attribute name="ProviderAdapterClass"&gt;org.jboss.jms.jndi.JNDIProviderAdapter&lt;/attribute&gt;
          &lt;attribute name="FactoryRef"&gt;jms/RemoteConnectionFactory&lt;/attribute&gt;
          &lt;attribute name="QueueFactoryRef"&gt;jms/RemoteConnectionFactory&lt;/attribute&gt;
          &lt;attribute name="TopicFactoryRef"&gt;jms/RemoteConnectionFactory&lt;/attribute&gt;
          &lt;attribute name="Properties"&gt;         java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory  
  
              java.naming.provider.url=remote://localhost:4447
              java.naming.security.principal=ramguest 
              java.naming.security.credentials=password 
          &lt;/attribute&gt;
      &lt;/mbean&gt;    
      &lt;mbean code="org.jboss.jms.server.bridge.BridgeService" name="jboss.jms:service=Bridge,name=LegayBridgeSend" xmbean-dd="xmdesc/Bridge-xmbean.xml"&gt;            
          &lt;depends optional-attribute-name="SourceProviderLoader"&gt;jboss.messaging:service=JMSProviderLoader,name=JMSProvider&lt;/depends&gt;
          &lt;depends optional-attribute-name="TargetProviderLoader"&gt;jboss.messaging:service=JMSProviderLoader,name=RemoteJBossMQProvider&lt;/depends&gt;
          &lt;attribute name="SourceDestinationLookup"&gt;BalaQueue&lt;/attribute&gt;  
          &lt;attribute name="TargetDestinationLookup"&gt;java:jboss/exported/jms/queue/ram&lt;/attribute&gt;
          &lt;attribute name="QualityOfServiceMode"&gt;1&lt;/attribute&gt;
          &lt;attribute name="MaxBatchSize"&gt;1&lt;/attribute&gt;
          &lt;attribute name="MaxBatchTime"&gt;-1&lt;/attribute&gt;
          &lt;attribute name="FailureRetryInterval"&gt;10000&lt;/attribute&gt;
          &lt;attribute name="MaxRetries"&gt;-1&lt;/attribute&gt;
          &lt;attribute name="AddMessageIDInHeader"&gt;false&lt;/attribute&gt;    
          &lt;attribute name="TargetUsername"&gt;ramguest&lt;/attribute&gt;
          &lt;attribute name="TargetPassword"&gt;password&lt;/attribute&gt;   
      &lt;/mbean&gt; 
  &lt;/server&gt; 
  </code></pre>
  
  <p>When I start jboss5 I am getting exception </p>
  
  <pre><code>WARN  [Bridge] jboss.jms:name=LegayBridgeSend,service=Bridge Failed to set up connections
  javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
          at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1678)
          at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1795)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
          at javax.naming.InitialContext.lookup(InitialContext.java:392)
          at org.jboss.jms.server.bridge.JNDIFactorySupport.createObject(JNDIFactorySupport.java:66)
          at org.jboss.jms.server.bridge.JNDIDestinationFactory.createDestination(JNDIDestinationFactory.java:45)
          at org.jboss.jms.server.bridge.Bridge.setupJMSObjects(Bridge.java:953)
          at org.jboss.jms.server.bridge.Bridge.setupJMSObjectsWithRetry(Bridge.java:1223)
          at org.jboss.jms.server.bridge.Bridge.access$1600(Bridge.java:68)
          at org.jboss.jms.server.bridge.Bridge$FailureHandler.run(Bridge.java:1569)
          at java.lang.Thread.run(Thread.java:662)
  Caused by: java.net.SocketTimeoutException: Receive timed out
          at java.net.PlainDatagramSocketImpl.receive0(Native Method)
          at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:145)
          at java.net.DatagramSocket.receive(DatagramSocket.java:725)
          at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1647)
  </code></pre>
  
  <p>Can anybody guide me please...</p>