簡體   English   中英

使用Java連接到IBM MQ 7.5的問題

[英]Issues with connecting to ibm mq 7.5 using java

我是ibm mq的新手,我發現與mb相關的文檔或書籍很少,我發現的唯一一部是2004年寫的“ WebSphere MQ Using Java”。但是現實世界發生了很大變化。 我安裝在RedHat Linux 64位驗證MQ服務器7.5成功地根據

我還創建了隊列管理器myqm1 ,隊列LQ.TEST ,通道JAVA.CHANNEL ,並通過服務器上的命令行進行了一些測試以確保它們正常工作。 但是,當我在Windows XP上安裝mq客戶端並在Java代碼下編寫以下代碼時,它始終會引發exception:com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'

我的代碼:

導入com.ibm.mq. *; 導入com.ibm.mq.constants.MQConstants;

/ ** *簡單的示例程序* /公共類MQSample {

 // code identifier static final String sccsid = "@(#) MQMBID sn=p000-L120604 su=_H-IvIK4nEeGko6IWl3MDhA pn=MQJavaSamples/wmqjava/MQSample.java"; // define the name of the QueueManager private static final String qManager = "myqm1"; // and define the name of the Queue private static final String qName = "LQ.TEST"; /** * Main entry point * * @param args - command line arguments (ignored) */ public static void main(String args[]) { try { MQEnvironment.hostname = "58.2.221.196"; MQEnvironment.channel = "JAVA.CHANNEL"; MQEnvironment.port = 1414; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES); MQEnvironment.userID = "mqm"; MQEnvironment.password = "mqm"; MQEnvironment.CCSID = 1208; // Create a connection to the QueueManager System.out.println("Connecting to queue manager: " + qManager); MQQueueManager qMgr = new MQQueueManager(qManager); // Set up the options on the queue we wish to open int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT; // Now specify the queue that we wish to open and the open options System.out.println("Accessing queue: " + qName); MQQueue queue = qMgr.accessQueue(qName, openOptions); // Define a simple WebSphere MQ Message ... MQMessage msg = new MQMessage(); // ... and write some text in UTF8 format msg.writeUTF("Hello, World!"); // Specify the default put message options MQPutMessageOptions pmo = new MQPutMessageOptions(); // Put the message to the queue System.out.println("Sending a message..."); queue.put(msg, pmo); // Now get the message back again. First define a WebSphere MQ // message // to receive the data MQMessage rcvMessage = new MQMessage(); // Specify default get message options MQGetMessageOptions gmo = new MQGetMessageOptions(); // Get the message off the queue. System.out.println("...and getting the message back again"); queue.get(rcvMessage, gmo); // And display the message text... String msgText = rcvMessage.readUTF(); System.out.println("The message is: " + msgText); // Close the queue System.out.println("Closing the queue"); queue.close(); // Disconnect from the QueueManager System.out.println("Disconnecting from the Queue Manager"); qMgr.disconnect(); System.out.println("Done!"); } catch (MQException ex) { ex.printStackTrace(); System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode + " Reason Code " + ex.reasonCode); } catch (java.io.IOException ex) { System.out.println("An IOException occured whilst writing to the message buffer: " + ex); } return; } } 

有人可以給我開個燈嗎? 我很沮喪

為了擴展Shashi的答案,自WMQ V7.1起,默認的CHLAUTH規則會阻止所有SVRCONN通道上的所有訪問, 並且會阻止所有SVRCONN通道上的管理訪問。 如果您確實想以mqm連接到JAVA.CHANNEL ,則將需要覆蓋這兩種行為。

如果您實際上願意允許使用管理用戶ID到QMgr進行未經身份驗證的遠程連接,則可以選擇完全禁用CHLAUTH規則。 您可以通過在runmqsc發出ALTER QMGR CHLAUTH(DISABLED)命令來執行此操作,但是不建議這樣做,因為它使QMgr可以使用WMQ管理用戶ID匿名執行遠程代碼。 但是,這就是您似乎想做的。

推薦的方法是使用管理性ID。 例如,如果您使用一個私有組(也稱為mquser mquser了一個名為mquser的ID,那么您可以授予它連接和查詢QMgr的權限,並打開指定的隊列進行放置,獲取,瀏覽和查詢。 由於該ID不是管理性的,因此在未經身份驗證的通道上使用相對安全。 您可以更改代碼以將ID指定為mquser而不是mqm ,然后使用CHLAUTH規則允許連接。 例如:

SET CHLAUTH('JAVA.CHANNEL') TYPE(USERMAP) +
    CLNTUSER('mquser') USERSRC(MAP) +
    MCAUSER('mquser') ACTION(ADD) 

上面的規則告訴QMGR“當你看到從一個連接mquser上ID JAVA.CHANNEL ,然后設置MCAUSER到mquser和允許的連接。”

授予權限時,請記住要在組而不是用戶上授予權限。 例如,如果使用setmqaut ,則使用-g選項而不是-p選項。 如果授權錯誤有任何問題,您可以使用事件消息輕松解決。 首先,使用ALTER QMGR AUTHOREV(ENABLED)啟用事件。 這將導致QMgr向SYSTEM.ADMIN.QMGR.EVENT隊列中發送事件消息。 您可以使用SupportPac MH05SupportPac MS0P來分析事件消息。 對於任何給定的授權事件,該消息都會告訴您請求訪問的ID,API調用(連接,打開,關閉等),針對其進行調用的對象以及所使用的確切選項。

在WMQ V7.1之前,WebSphere MQ允許所有遠程連接,甚至包括匿名的管理連接。 盡管這使您可以輕松連接,但是在當今更加不利的網絡環境中,在QMgr的主機服務器上遠程匿名執行代碼的能力被視為無法接受的安全風險。 因此,現在將新的QMgr設置為默認情況下不允許任何遠程管理訪問。 作為管理員,這要求您顯式禁用安全性以獲取舊行為或顯式設置安全訪問。

在MQ v7.5中,默認情況下禁止訪問隊列管理器。 您需要為創建的通道JAVA.CHANNEL創建通道身份驗證記錄,以允許用戶訪問隊列管理器。 請點擊此鏈接以獲取有關頻道身份驗證記錄的更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM