java websphere MQ

前端 未结 3 747
逝去的感伤
逝去的感伤 2021-02-06 13:15

My aim is to put n number of messages in a for loop to a WebSphere MQ queue using WebSphere MQ java programming.

My java program will run as a standalone program.

相关标签:
3条回答
  • 2021-02-06 13:21

    WMQ supports both local and global (XA) units of work. The local units of work are available simply by specifying the option. Global XA transactions require a transaction manager, as mentioned by keithkreissl in another answer.

    For what you described, a POJO doing messaging under syncpoint, specify MQC.MQGMO_SYNCPOINT in your MQGetMessageOptions. When you are ready to commit, issue the MQQManager.commit() or MQQManager.backout() call.

    Note that the response and doc provided by ggrandes refers to the JMS and not Java classes. The Java classes use Java equivalents of the WMQ procedural API, can support many threads (doc) and even provide connection pooling (doc). Please refer to the Java documentation rather than the JMS documentation for the correct behavior. Also, I've linked to the WMQ V7.5 documentation which goes with the latest WMQ Java V7.5 client. The later clients have a lot more local functionality (tracing, flexible install path, MQClient.ini, etc.) and work with back-level QMgrs. It is highly recommended to be using the latest client and the download is free.

    0 讨论(0)
  • 2021-02-06 13:32

    If you have access to a transaction manager and more importantly an XATransaction wired up to your MQ access, you can start a transaction at the beginning of your message processing put all the messages on the queue then commit the transaction. Using the XATransactions it will not put any messages until the transaction commits. If you don't have access to that, you can do a little more plumbing by placing your messages in a local data object, wrap your code in a try/catch if no exceptions iterate through the local data object sending the messages. The issue with the later approach is that it will commit all your other processing but if a problem occurs in the sending of messages your other processing will not be rolled back.

    0 讨论(0)
  • 2021-02-06 13:33

    you only need to create a session with transaction enabled.

    Session session;
    // ...
    boolean transacted = true;
    session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
    try {
        // ...do things...
        session.commit();
    } catch (Exception e) {
        session.rollback();
    }
    // ...
    

    WARN-NOTE: Sessions are not thread-safe ;-)

    • Doc Websphere MQ/JMS
    0 讨论(0)
提交回复
热议问题