我们在本地主机上运行独立的JBoss 7.2并使用standalone-full.xml 但是在轻量级版本中,以便删除任何未使用的内容 - 例如 消息传递部分已删除。
但是现在我试图通过使用jms来对队列进行MessageDrivenBean。 我首先将以下内容添加到standalone-full.xml:
<extensions>
<extension module="org.jboss.as.messaging"/>
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
<persistence-enabled>true</persistence-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>
<security-domain>XXSecurityDomain</security-domain>
<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>
<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="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>
</hornetq-server>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:100}">
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-throughput" port="5455"/>
接下来,我使用了之前已经运行的现有servlet,并对其进行了修改:
public class XRequestServlet extends HttpServlet
Context mQueueContext = null;
ConnectionFactory mConnectionFactory = null;
Connection mConnection = null;
public void init() throws ServletException {
try {
log.info("init()");
mQueueContext = new InitialContext();
mConnectionFactory = (ConnectionFactory) mQueueContext.lookup("/ConnectionFactory");
} catch (NamingException e) {
e.printStackTrace();
}
}
public void doPost(WebSession pWebSession, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("doPost()");
String vDestinationName = "java:jboss/exported/jms/queue/testQueue";
PrintWriter vOut = response.getWriter();
try {
log.info("1");
mConnection = mConnectionFactory.createConnection();
log.info("1.5");
Queue vQueue = (Queue) mQueueContext.lookup(vDestinationName);
log.info("2");
为了测试它我在firefox中使用RESTClient插件,我可以看到我的请求 输入doPost(),我看到记录doPost(),1和1.5但是在尝试创建时 队列失败。 在jboss日志中,我收到以下错误:
javax.naming.NameNotFoundException:jms / queue / testQueue - service jboss.naming.context.java.jboss.exported.jms.queue.testQueue
有人可以给我建议需要做些什么吗?
答案 0 :(得分:2)
我没有查看配置的其余部分,但是你得到的错误的直接原因是你似乎没有在JBoss中配置任何队列,所以当你尝试使用它来查找它时mQueueContext.lookup
抛出异常。
队列配置在jms-destinations下,如下所示:
<subsystem xmlns="urn:jboss:domain:messaging:1.0">
[...]
<jms-destinations>
<jms-queue name="testQueue">
<entry name="jms/queue/test"/>
<entry name="java:jboss/exported/jms/queue/test"/>
</jms-queue>
[...]
</subsystem>
有关在JBoss 7下设置JMS的更多文档,请参阅https://docs.jboss.org/author/display/AS72/Messaging+configuration#Messagingconfiguration-JMSQueuesandTopics