[英]JMS message to remote server
我需要將消息發送到遠程服務器的隊列(運行“ JBoss MQ”),以便它可以處理消息並對其執行操作。
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://192.168.1.131.129:1299");
InitialContext jndiContext = new InitialContext(properties);
//[2] Look up connection factory and queue.
ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext.lookup("UIL2XAConnectionFactory");
Queue queue = (Queue)jndiContext.lookup("Queue/DataTransferQueue");
但是運行上面的代碼時出現異常:(即使我可以ping通遠程服務器)。
javax.naming.CommunicationException: Could not obtain connection to any of these urls: 192.168.1.131.129:1299 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.1.131.129:1299
連接到遠程隊列有什么特別的事情嗎?
您使用的IP地址不正確:192.168.1.131.129有5個數字,只能有4個。
我通過使用以下過程參數重啟JBoss服務器來解決了這個問題:
-b 0.0.0.0
默認情況下,JBoss服務器已啟動,僅允許本地連接。 通過使用前面提到的參數啟動它,可以指示它接受遠程連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.