Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:01:34+00:00 2026-06-15T05:01:34+00:00

I am receiving messages from aActive MQ queue. Is there a way to receive

  • 0

I am receiving messages from aActive MQ queue.

Is there a way to receive a number of messages in one time? or is that have to be done with a loop?

Further more, if i want to take say 30 messages run a procedure, and only if that procedure works return a message.acknowledge(); for all of them.

I mean i dont want to erase those 30 from the queue if the procedure fails.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:01:34+00:00Added an answer on June 15, 2026 at 5:01 am

    You’ll have to do it in a loop. Usually, it’s best to use message-driven beans for consuming messages, but it’s not suitable for this case, because they take message by message and you cannot specify the exact number. Thus, use MessageConsumer and manual transactions:

    @Resource
    UserTransaction utx;
    
    @Resource(mappedName="jms/yourConnectionFactory");
    ConnectionFactory cf;
    
    @Resource(mappedName="jms/yourQueue");
    Queue queue;
    
    ..    
    Connection conn = null;
    Session s = null;
    MessageConsumer mc = null;
    try {
        utx.begin();
        conn = cf.createConnection();
        s = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE); //TRANSACTIONAL SESSION!
        mc = s.createConsumer(queue);
        conn.start(); // START CONNECTION'S DELIVERY OF INCOMING MESSAGES
        for(int i=0; i<30; i++)
        {
              Message msg = mc.receive();
              //BUSINESS LOGIC
        }
        utx.commit();
    } catch(Exception ex) {
      ..
    } finally { //CLOSE CONNECTION, SESSION AND MESSAGE CONSUMER
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server application receiving messages from a JMS queue. And client applications
In our project we have requirement that, after receiving sms message from third party
I have a ruby script that is simultaneously and asynchronously receiving and displaying messages
I'm receiving messages from a JMS MQ queue which are supposedly utf-8 encoded. However
I have an application which will be receiving messages from another application. These messages
I have a TCP socket client receiving messages (data) from a server. messages are
For instance, I have a model class which handles receiving bluetooth messages from other
I have an orchestration which is receiving messages from the message box of type
I have an application that consumes messages from a JMS topic. As part of
How do you conserve memory when receiving messages from POSIX queues? It seems that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.