Salve a tutti.
Il problema è il seguente:
ci sono più pc in rete che devono comunicare tramite un unico topic jms
risiedente su un pc sul quale è attivo jboss.
Ho provato con dei client sender e receiver semplici (scopiazzati dal tutorial
di Jms) e non riesco a farli comunicare…
In locale funziona tutto ma se provo ad indirizzare i client verso il pc sul
quale è attivo jboss (il cui ip è 192.168.65.127) la musica cambia.
Allora riporto i client e poi l’errore che si verifica quando provo a farli
funzionare con un topic remoto (ConnectionFactory e Topic utilizzati sono quelli
di default di Jboss):
*************** ERRORE *******************************codice:// ******** PUBLISHER ***************************** import java.util.Hashtable; import javax.jms.*; import javax.naming.*; public class Publisher { public static void main(String[] args) { Context jndiContext = null; TopicConnectionFactory topicConnectionFactory = null; TopicConnection topicConnection = null; TopicSession topicSession = null; Topic topic = null; TopicPublisher topicPublisher = null; TextMessage message = null; final int NUM_MSGS = 20; try { Hashtable props = new Hashtable(); props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); props.put(javax.naming.Context.PROVIDER_URL, "192.168.65.127:1099"); jndiContext = new InitialContext(props); } catch (NamingException e) { System.out.println("Could not create JNDI API " + "context: " + e.toString()); e.printStackTrace(); System.exit(1); } try { topicConnectionFactory = (TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory"); topic = (Topic) jndiContext.lookup("topic/testTopic"); } catch (NamingException e) { System.out.println("JNDI API lookup failed: " + e.toString()); e.printStackTrace(); System.exit(1); } try { topicConnection = topicConnectionFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicPublisher = topicSession.createPublisher(topic); message = topicSession.createTextMessage(); for (int i = 0; i < NUM_MSGS; i++) { message.setText("This is message " + (i + 1)); System.out.println("Publishing message: " + message.getText()); topicPublisher.publish(message); } } catch (JMSException e) { System.out.println("Exception occurred: " + e.toString()); } finally { if (topicConnection != null) { try { topicConnection.close(); } catch (JMSException e) {} } } } } // ******** END PUBLISHER *********************** // ******** SUBSCRIBER ************************** import javax.jms.*; import javax.naming.*; import java.io.*; import java.util.Hashtable; public class Subscriber { public static void main(String[] args) { Context jndiContext = null; TopicConnectionFactory topicConnectionFactory = null; TopicConnection topicConnection = null; TopicSession topicSession = null; Topic topic = null; TopicSubscriber topicSubscriber = null; TextListener topicListener = null; TextMessage message = null; InputStreamReader inputStreamReader = null; char answer = '\0'; try { Hashtable props = new Hashtable(); props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); props.put(javax.naming.Context.PROVIDER_URL, "192.168.65.127:1099"); jndiContext = new InitialContext(props); } catch (NamingException e) { System.out.println("Could not create JNDI API " + "context: " + e.toString()); e.printStackTrace(); System.exit(1); } try { topicConnectionFactory = (TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory"); topic = (Topic) jndiContext.lookup("topic/testTopic"); } catch (NamingException e) { System.out.println("JNDI API lookup failed: " + e.toString()); e.printStackTrace(); System.exit(1); } try { topicConnection = topicConnectionFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicSubscriber = topicSession.createSubscriber(topic); topicListener = new TextListener(); topicSubscriber.setMessageListener(topicListener); topicConnection.start(); System.out.println("To end program, enter Q or q, " + "then <return>"); inputStreamReader = new InputStreamReader(System.in); while (!((answer == 'q') || (answer == 'Q'))) { try { answer = (char) inputStreamReader.read(); } catch (IOException e) { System.out.println("I/O exception: " + e.toString()); } } } catch (JMSException e) { System.out.println("Exception occurred: " + e.toString()); } finally { if (topicConnection != null) { try { topicConnection.close(); } catch (JMSException e) {} } } } }// ******** END SUBSCRIBER ******************* // ******** LISTENERER ************************ import javax.jms.*; public class TextListener implements MessageListener { public void onMessage(Message message) { TextMessage msg = null; try { if (message instanceof TextMessage) { msg = (TextMessage) message; System.out.println("Reading message: " + msg.getText()); } else { System.out.println("Message of wrong type: " + message.getClass().getName()); } } catch (JMSException e) { System.out.println("JMSException in onMessage(): " + e.toString()); } catch (Throwable t) { System.out.println("Exception in onMessage():" + t.getMessage()); } } } // ******** END LISTENERER ***********************
Il seguente è l’errore a run time (identico per publisher e subscriber sulla
istruzione topicConnectionFactory = (TopicConnectionFactory)
jndiContext.lookup("TopicConnectionFactory")
JNDI API lookup failed: javax.naming.CommunicationException: Could not obtain
connection to any of these urls: 192.168.65.127:1099 and discovery failed with
error: javax.naming.CommunicationException: Receive timed out [Root exception is
java.net.SocketTimeoutException: Receive timed out] [Root exception is
javax.naming.CommunicationException: Failed to connect to server
192.168.65.127:1099 [Root exception is javax.naming.ServiceUnavailableException:
Failed to connect to server 192.168.65.127:1099 [Root exception is
java.net.ConnectException: Connection refused: connect]]]
javax.naming.CommunicationException: Could not obtain connection to any of these
urls: 192.168.65.127:1099 and discovery failed with error:
javax.naming.CommunicationException: Receive timed out [Root exception is
java.net.SocketTimeoutException: Receive timed out] [Root exception is
javax.naming.CommunicationException: Failed to connect to server
192.168.65.127:1099 [Root exception is javax.naming.ServiceUnavailableException:
Failed to connect to server 192.168.65.127:1099 [Root exception is
java.net.ConnectException: Connection refused: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingCo ntext.java:1414)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at Subscriber.main(Subscriber.java:39)
Caused by: javax.naming.CommunicationException: Failed to connect to server
192.168.65.127:1099 [Root exception is javax.naming.ServiceUnavailableException:
Failed to connect to server 192.168.65.127:1099 [Root exception is
java.net.ConnectException: Connection refused: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingCo ntext.java:1385)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server
192.168.65.127:1099 [Root exception is java.net.ConnectException: Connection
refused: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:243)
... 5 more
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 java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:84)
at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:77)
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:239)
... 5 more
*************** *******************************************
cosa devo fare?????![]()


Rispondi quotando