javamq,javamqtt

本文目錄一覽:

java mq消息包括哪些框架

websphere mq : 用於傳輸信息 具有跨平台的功能。 1 安裝websphere mq 並啟動 2 websphere mq 建立 queue Manager (如:MQSI_SAMPLE_QM) 3 建立queue 類型選擇 Local類型 的 (如lq ) 3 建立channels 類型選擇Server Connection (如BridgeChan…

在JAVA開發中,如何查詢MQ中的隊列句柄狀態?

你用的是IBM MQ還是Apache的? 一般通過JAVA的JMS可以取得。

例如IBM MQ里有個MQQueue 對象

// 獲取隊列實例

MQQueue queue = qMgr.accessQueue(“TEST_QUEUE”, openOptions);

//獲取當前隊列最長消息的長度

queue.getMaximumMessageLength()

//獲取當前隊列最長深度

queue.getMaximumMessageLength()

等等功能都是提供的,具體你下載個WebSphere MQ API 找到MQQueue一看便知。

java事務中調用mq,如果事務回滾,消息會被撤回嗎

回。java事務中調用mq是公司開發的平台程序,程序內設置了撤回語言,如果事務回滾消息會被撤回處理,Java的事務處理,如果對資料庫進行多次操作,每一次的執行或步驟都是一個事務。

mq java 怎麼判斷隊列為空

MQException

該類包含WebSphere MQ 完成代碼和錯誤代碼常量的定義。以MQCC_開始的常量是WebSphere MQ 完成代碼,而以MQRC_開始的常量則是WebSphere MQ 原因代碼。只要出現WebSphere MQ

錯誤,就會給出MQException。

MQGetMessageOptions

該類包含控制MQQueue.get()方法行為的選項。

MQManagedObject

該類是MQQueueManager、MQQueue 和MQProcess 類的超類。它提供查詢並設置這些資源屬性的能力。

——解決方案——————–

去取一次,得到 2033 錯誤就是沒有消息符合你的條件。

使用 PCF 查詢隊列資料:

/**

* @return current depth of queue connected currently.

* @throws Exception

*/

public QueueInfo queryQueueInfo() throws Exception {

if (!checkStatus2(this.queueManager)) {

throw new IllegalStateException(“Not Connected to queue manager.”);

}

PCFMessageAgent agent = null;

try {

agent = new PCFMessageAgent(this.queueManager);

// Inquiry Queue Name Current Depth.

int[] attrs = {

CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH,

CMQC.MQIA_OPEN_INPUT_COUNT, CMQC.MQIA_OPEN_OUTPUT_COUNT,

CMQC.MQIA_Q_TYPE, CMQC.MQIA_DEFINITION_TYPE, CMQC.MQIA_INHIBIT_GET,

CMQC.MQIA_INHIBIT_PUT };

PCFParameter[] parameters = {

new MQCFST(CMQC.MQCA_Q_NAME , getInputQueue().getText().trim()),

new MQCFIL(CMQCFC.MQIACF_Q_ATTRS , attrs) };

// logger.log(“Querying current depth of current queue.”);

MQMessage[] responses = agent.send(CMQCFC.MQCMD_INQUIRE_Q, parameters);

QueueInfo info = new QueueInfo();

for (int i = 0; i responses.length; i++) {

MQCFH cfh = new MQCFH(responses[i]);

// Check the PCF header (MQCFH) in the response message

if (cfh.reason == 0) {

String name = “”;

Integer depth = new Integer(0);

for (int j = 0; j cfh.parameterCount; j++) { // Extract what we want from the returned attributes

PCFParameter p = PCFParameter.nextParameter(responses[i]);

switch (p.getParameter()) {

case CMQC.MQCA_Q_NAME:

name = (String) p.getValue();

info.name = name;

break;

case CMQC.MQIA_CURRENT_Q_DEPTH:

depth = (Integer) p.getValue();

info.depth = depth.intValue();

break;

case CMQC.MQIA_OPEN_INPUT_COUNT:

Integer inputCount = (Integer) p.getValue();

info.inputCount = inputCount.intValue();

break;

case CMQC.MQIA_OPEN_OUTPUT_COUNT:

Integer outputCount = (Integer) p.getValue();

info.outputCount = outputCount.intValue();

break;

case CMQC.MQIA_Q_TYPE:

info.type = ((Integer) p.getValue()).intValue();

break;

case CMQC.MQIA_DEFINITION_TYPE:

info.definitionType = ((Integer) p.getValue()).intValue();

break;

case CMQC.MQIA_INHIBIT_PUT:

info.putNotAllowed = ((Integer) p.getValue()).intValue() == 1;

break; case CMQC.MQIA_INHIBIT_GET:

info.getNotAllowed = ((Integer) p.getValue()).intValue() == 1;

default:

}

}

// System.out.println(“Queue ” + name + ” curdepth ” + depth);

return info;

} else {

System.out.println(“PCF error:\n” + cfh);

// Walk through the returned parameters describing the error

for (int j = 0; j cfh.parameterCount; j++) {

System.out.println(PCFParameter.nextParameter(responses[0]));

}

throw new Exception(“PCF Error [reason :” + cfh.reason + “]”);

}

}

return null;

} catch (Exception e) {

throw e;

} finally {

if (agent != null) {

try {

agent.disconnect();

} catch (Exception e) {

logger.log(e);

}

}

}

java 監聽mq消息 底層是用線程實現的嗎

不是通過線程實現的,它是通過一種註冊–通知機制實現的。在java的設計模式中,有一種模式叫:觀察者模式,和這個類似。舉個例子,本例子是一個簡單的監聽當數據發生變化時要做的操作。

1,我們先定義一個介面,可以讓多個監聽者實現pre t=”code” l=”java”public interface IDataListen {

public void update(Object event,Object msg);

}2,實現一監聽者

pre t=”code” l=”java”public class DataListen implements IDataListen{

@Override

public void update(Object event, Object arg) {

// TODO Auto-generated method stub

System.out.println(“數據發生了變化”);

}

}3,被監聽者

pre t=”code” l=”java”public class DataManager{

private ListIDataListen listenList = new ArrayList();

public void notifyListen(Object event,Object msg){

for(IDataListen dataListen : listenList){

dataListen.update(null, null);

}

}

public void addListen(IDataListen dataListen){

listenList.add(dataListen);

}

public void updateData(Object msg){

this.notifyListen(null, msg);

}

public static void main(String[] args) {

DataManager dataManager = new DataManager();

IDataListen dataListen1 = new DataListen();

IDataListen dataListen2 = new DataListen();

dataManager.addListen(dataListen1);

dataManager.addListen(dataListen2);

dataManager.updateData(“aaa”);

}

}main方法裡面是監聽的應用。這樣就可以監聽DataManager中的updateData行為了,當有數據發生變化時,就可以即時被監聽者收到。

java使用mq get api從mq中取數據怎樣觸發偵聽器連續取數據

{

//前面是準備管理器和隊列

MQQueueManager qMgr = new MQQueueManager(qManager);

int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INQUIRE;

MQQueue queue = qMgr.accessQueue(qName, openOptions);

MQMessage rcvMessage = new MQMessage();

MQGetMessageOptions gmo = new MQGetMessageOptions();

gmo.options = gmo.options + MQConstants.MQGMO_WAIT + MQConstants.MQGMO_SYNCPOINT;

//讀取五秒超時,這裡目的是要有個讀取阻塞,和Socket編程類似。

gmo.waitInterval = 5000;

queue.get(rcvMessage, gmo);

//後面就是操作消息的部分【略】

}catch(Exception e){{

//前面是準備管理器和隊列

MQQueueManager qMgr = new MQQueueManager(qManager);

int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INQUIRE;

MQQueue queue = qMgr.accessQueue(qName, openOptions);

MQMessage rcvMessage = new MQMessage();

MQGetMessageOptions gmo = new MQGetMessageOptions();

gmo.options = gmo.options + MQConstants.MQGMO_WAIT + MQConstants.MQGMO_SYNCPOINT;

//讀取五秒超時,這裡目的是要有個讀取阻塞,和Socket編程類似。

gmo.waitInterval = 5000;

queue.get(rcvMessage, gmo);

//後面就是操作消息的部分【略】

}catch(Exception e){

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/285389.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-22 15:44
下一篇 2024-12-22 15:44

相關推薦

  • JAVAmq技術詳解

    一、JAVAmqtt JAVAmqtt是基於MQTT協議的輕量級消息協議,實現了發布/訂閱模式的消息傳遞。在JAVAmq中,通過使用JAVAmqtt客戶端,開發人員可以方便地在設備…

    編程 2024-11-19
  • 關於javamqtt的信息

    本文目錄一覽: 1、Java項目:mqtt發送的數據如何保存到資料庫里? 2、Java/Android:關於ActiveMQ與MQTT的關係是什麼? 3、mqtt 伺服器搭建需要用…

    編程 2024-11-11

發表回復

登錄後才能評論