jka_dk
jka_dk

Reputation: 451

JBoss 7.2 jms messaging queue

We're running a standalone JBoss 7.2 on my localhost and using the standalone-full.xml but in a lightweight version so that anything that isnt used is removed - for instance the messaging sections were removed.

But now im trying to do a MessageDrivenBean with a queue by using the jms. I started by adding following to the 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"/>

Next i used an existing servlet which was already working before, and modified it :

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");

To test it i use a RESTClient plugin in firefox and i can see the my request enters doPost() and i see logging doPost(), 1 and 1.5 but at trying to create a queue fails. In the jboss log i get following error :

javax.naming.NameNotFoundException: jms/queue/testQueue -- service jboss.naming.context.java.jboss.exported.jms.queue.testQueue

Can someone give me advice what needs to be done ??

Upvotes: 0

Views: 1880

Answers (1)

matt freake
matt freake

Reputation: 5090

I haven't reviewed the rest of your config, but the immediate cause of the error you are getting, is that you don't seem to have configured any queues in JBoss, so when you try to look it up using the mQueueContext.lookup the exception is thrown.

Queues are configured under jms-destinations like this:

<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>

See https://docs.jboss.org/author/display/AS72/Messaging+configuration#Messagingconfiguration-JMSQueuesandTopics for more documentation on setting up JMS under JBoss 7

Upvotes: 2

Related Questions