2016-11-22 24 views
0

我當前的應用程序邏輯使用'PROCESS'WMQ隊列的深度來確定作業是否由IIB9工作流程處理。如果工作流程正在處理消息,則應用程序將等待該工作流程結束。一旦工作流程結束,將使用GET操作清空'PROCESS'隊列,應用程序將按順序發送其他消息以進行處理。我使用JMS選擇器來區分工作流並行處理的多條消息。JMS API無法瀏覽消息,IBM API可以

問題在於確定隊列的深度。 JMS API將深度設置爲0,而IBM API將深度設置爲1(這是預期的)。不幸的是,我不能使用IBM API作爲我的邏輯使用一些複雜的消息選擇器。

有沒有人看到這種奇怪的行爲?請注意,在進行尺寸檢查時,IIB9工作流程正在進行中。是否有一個設置需要調整?

JMS規範(消息選擇爲清楚起見移除):

public class QDepthJMS { 

public static void main(String[] a) throws Exception { 
    MQConnectionFactory factory = new MQConnectionFactory(); 
    factory.setTransportType(WMQConstants.WMQ_CM_CLIENT); 
    factory.setQueueManager("QM01"); 
    factory.setHostName("10.10.98.15"); 
    factory.setPort(1414); 
    factory.setChannel("Java.Clients"); 

    MQConnection connection = (MQConnection) factory.createConnection(); 
    connection.start(); 

    MQSession session = (MQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 

    MQQueue queue = (MQQueue) session.createQueue("queue:///PROCESS"); 
    MQQueueBrowser browser = (MQQueueBrowser) session.createBrowser(queue); 

    Enumeration<Message> msgs = browser.getEnumeration(); 
    int count =0; 
    if (msgs.hasMoreElements()) { 
     msgs.nextElement(); 
     ++count; 
    } 

    System.out.println(count); 
} 
} 

IBM API(Check MQ queue depth):

public class QDepth { 

private final String host; 
private final int port; 
private final String channel; 
private final String manager; 
private final MQQueueManager qmgr; 

public QDepth(String host, int port, String channel, String manager) throws MQException { 
    this.host = host; 
    this.port = port; 
    this.channel = channel; 
    this.manager = manager; 
    this.qmgr = createQueueManager(); 
} 

public int depthOf(String queueName) throws MQException { 
    MQQueue queue = qmgr.accessQueue(queueName, MQC.MQOO_INQUIRE | MQC.MQOO_INPUT_AS_Q_DEF, null, null, null); 
    return queue.getCurrentDepth(); 
} 

@SuppressWarnings("unchecked") 
private MQQueueManager createQueueManager() throws MQException { 
    MQEnvironment.channel = channel; 
    MQEnvironment.port = port; 
    MQEnvironment.hostname = host; 
    MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES); 
    return new MQQueueManager(manager); 
} 

public static void main(String[] a) throws Exception { 
    QDepth qd = new QDepth("10.10.98.15, 1414, "Java.Clients", "QM01"); 
    System.out.println(qd.depthOf("PROCESS")); 
} 
} 

回答

2

你是不是比較 「就像似」 - IBM的API查詢隊列深度,即隊列中有多少消息,但JMS API正在瀏覽消息並對它們進行計數。有一個合理的原因是它們有所不同 - 通常的原因是有人在工作單元(同步點)下面放置了一條消息,但它尚未提交 - 因此,在運行IBM API時,它會說有1隊列中的消息(有...),但由於它尚未提交,因此它不可獲取/可瀏覽。

您可以通過的runmqsc DIS QSTATUS驗證這一點使用的runmqsc(也可能是GUI),並期待在UNCOM屬性 - 請參閱http://www-01.ibm.com/support/docview.wss?uid=swg21636775

+0

添加到賈森的回答是:JMS 1.1規範沒有描述任何API確定隊列深度。所以這並不奇怪。 – Shashi

+0

@JasonE,你的建議確實解決了這個問題。我處於交易(UOW)環境中,因此無法瀏覽消息。我在IIB9工作流上禁用了交易模式,問題已解決。 – Sandeep