Avatar billede fredand Forsker
13. juni 2017 - 17:27 Der er 3 kommentarer og
2 løsninger

How to send a JMS-message inside a JBoss 6

Hello Guys!

Do you got any example-code sending a JMS-message from a EJB to a queue inside the same server, of type JBoss 6?

We are migrating from JBoss 5 to JBoss 6 and our old code doesn't seem's to work.

Best regards
Fredrik
Avatar billede arne_v Ekspert
13. juni 2017 - 17:38 #1
Jeg har brugt denne med JBoss EAP 6.x / JBoss AS 7.x:


    @Resource(mappedName="java:/JmsXA")
    private ConnectionFactory cf;
    @Resource(mappedName="java:jboss/exported/jms/queue/testmanager")
    private Queue q;



            Connection c = cf.createConnection();
            Session ses = c.createSession(false,  Session.AUTO_ACKNOWLEDGE);
            MessageProducer sender = ses.createProducer(q);
            sender.send(ses.createObjectMessage(o));
            c.close();
Avatar billede arne_v Ekspert
13. juni 2017 - 17:41 #2
JBoss config:


<jms-queue name="testManagerQueue">
<entry name="queue/testmanager"/>
<entry name="java:jboss/exported/jms/queue/testmanager"/>
</jms-queue>
Avatar billede fredand Forsker
15. juni 2017 - 16:37 #3
Hello Arne!

I have finally tried out your code and it worked like a charm.

I never got it to work with the @Resource tag instead I did it like:
    Context context = new InitialContext();
    ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup( "java:/JmsXA" );
    //Queue queue = (Queue)context.lookup( "java:jboss/exported/jms/queue/myqueue" );
    Queue queue = (Queue)context.lookup( "java:/jms/queue/myqueue" );
       
        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false,  Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer( queue );
        TextMessage textMessage = session.createTextMessage( messagetext );
        messageProducer.send( textMessage );
        connection.close();

How ever as you see I also managed to post a message to the queue using the with out "exported". Correct me if I'm wrong but isn't the exported-paths more for remote client's? Or am I wrong?

Would you say it is wrong of me using the path without "exported"?

Best regards
Fredrik
Avatar billede arne_v Ekspert
15. juni 2017 - 18:43 #4
As long as the name points to the right queue then it should be fine.

I am not really uptodate on JBoss naming conventions.
Avatar billede fredand Forsker
23. august 2017 - 18:03 #5
Thanks for your help amigo!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester