gpt4 book ai didi

java - JMS 使用 jboss

转载 作者:行者123 更新时间:2023-11-29 08:58:42 26 4
gpt4 key购买 nike

我是 JMS 的新手。当我运行独立的 JMS 测试程序时,出现以下异常

我得到的异常如下:

**Channel end notification received, closing channel Channel ID 4995329b (inbound) of Remoting connection 0aff5851 to null**

我在下面附上我的代码供您引用:

QueueReceiver.java

package com.tradier.webservices.util;

import java.util.Hashtable;

import javax.jms.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class QueueReceive {
private final static String JNDI_FACTORY =
"org.jboss.naming.remote.client.InitialContextFactory";//org.jboss.naming.remote.client.InitialContextFactory
private final static String JMS_FACTORY = "java:jboss/exported/jms/RemoteConnectionFactory";
private final static String QUEUE = "queue/test";
private final static String jbossUrl = "remote://localhost:4447";

private static InitialContext getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, jbossUrl);
env.put(Context.SECURITY_PRINCIPAL, "jms");
env.put(Context.SECURITY_CREDENTIALS, "jboss1");
return new InitialContext(env);
}

public static void main(String[] args) throws Exception {
InitialContext ic = getInitialContext();
QueueConnectionFactory qconFactory = (QueueConnectionFactory)ic.lookup(JMS_FACTORY);
QueueConnection qcon = qconFactory.createQueueConnection("jms","jboss1");
QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ic.lookup(QUEUE);
QueueReceiver qreceiver = qsession.createReceiver(queue);

qcon.start();

TextMessage msg = (TextMessage)qreceiver.receive();
System.out.println("MYTEXT"+msg.getText());

qreceiver.close();
qsession.close();
qcon.close();
}
}

QueueSender.java

 package com.tradier.webservices.util;

import java.util.Hashtable;
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;
import javax.naming.NamingException;

public class QueueSend {
private final static String JNDI_FACTORY =
"org.jboss.naming.remote.client.InitialContextFactory";
private final static String JMS_FACTORY = "jms/RemoteConnectionFactory";
private final static String QUEUE = "jms/queue/test";
private final static String jbossUrl = "remote://localhost:4447";

private static InitialContext getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, jbossUrl);
env.put(Context.SECURITY_PRINCIPAL, "qtest");
env.put(Context.SECURITY_CREDENTIALS, "mytest");
return new InitialContext(env);
}

public static void main(String[] args) throws Exception {
InitialContext ic = getInitialContext();
try{
QueueConnectionFactory qconFactory =
(QueueConnectionFactory)ic.lookup(JMS_FACTORY);

QueueConnection qcon =
qconFactory.createQueueConnection("qtest","mytest");
QueueSession qsession = qcon.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ic.lookup(QUEUE);
QueueSender qsender = qsession.createSender(queue);

qcon.start();

TextMessage msg = qsession.createTextMessage();;
msg.setText("HelloWorld");
qsender.send(msg);

qsender.close();
qsession.close();
qcon.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

jboss standalone.xml 文件

<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
<persistence-enabled>true</persistence-enabled>
<security-enabled>false</security-enabled>
<journal-file-size>102400</journal-file-size>
<journal-min-files>2</journal-min-files>

<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
<netty-connector name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
</netty-connector>
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>

<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
<netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</netty-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>

<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>
netty
</connector-ref>
</broadcast-group>
</broadcast-groups>

<discovery-groups>
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>

<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty</connector-ref>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>

<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>
</security-settings>

<address-settings>
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<address-full-policy>BLOCK</address-full-policy>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<redistribution-delay>1000</redistribution-delay>
</address-setting>
</address-settings>

<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="RemoteConnectionFactory"/>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>

<jms-destinations>
<jms-queue name="testQueue">
<entry name="queue/test"/>
<entry name="java:jboss/exported/jms/queue/test"/>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>

帮我解决这个问题。 提前致谢。

最佳答案

你能澄清一下你在哪里得到这个错误吗? 在 Sender 程序或 Receiver 程序中?这通常发生在您的 Sender 本身失败并终止时,但您的 Receiver 仍在等待接收连接。在这种情况下,上述错误会出现在接收方的控制台输出中,而主要异常会显示在发送方的控制台中。

这种情况下的主要异常可能是由于用户不存在(比如在 ApplicationRealm 中)或用户可能没有正确的角色而导致的安全异常。

关于java - JMS 使用 jboss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com