Use C # programming to send WebSphere MQ 5.3 Windows Client Messages to Linux Server

xiaoxiao2021-03-06  58

The first is to install the client and server side of the MQ, which is justified. The client can download it to the IBM website is free. The server side, you have pirated, of course, there is no problem, if you don't only buy IBM. I can't help it. After installation, you also need to install the IBM to develop the installation package of the MQ program under .NET, you can also download on the IBM website: WebSphere MQ SupportPac launches a new toolkit, MA7P. This kit provides a development interface similar to the MQ C API, which can be developed on the .NET platform for WebSphere MQ. The supportPac can be downloaded under the following URL: http://www-3.ibm.com/software/integration/support/supportpacs/individual/ma7p.html After installation, you need to create a new ASPNET user on Linux, this user is You run the user using the ASP.NET program, if you don't use this user to run the .NET program, you will need to create a new one of your own users on Linux. Next is a new server channel and a local queue. This will only have a program left. The following is a simple introduction to the use of .NET development MQ applications for example. You do not need to specify whether you use the MQ client link library or use the MQ server-side link library or use the MQ server-side link library, .NET automatically selects the connection according to the way you use the queue manager in the program. . Initialization: The application starts to import MQ packets: use ibm.wmq; connection / disconnect queue manager: MA7P provides Queue Manager class MQQueUemanager, the application connection queue manager is implemented by the constructor of MQQueueManager. There are five classes MQQueueManager constructors are: public MQQueueManager (): directly create a queue manager object and connected to the local default queue manager; public MQQueueManager (MQConnectOptions mqcmo): public MQQueueManager (String queueManagerName): the connection named QueueManagerName the queue manager; public MQQueueManager (String queueManagerName, MQConnectOptions mqcno): option to connect mqcno connection queue manager named queueManagerName of; public MQQueueManager (String queueManagerName, String channel, String conname): channel to channel, the connection name connection name conname Queue Managername's queue manager. The application does not need to consider using the client link library or the server-side link library. The MA7P will automatically select the dynamic link library based on the connection used. After the queue manager object construct is completed, the connection to the queue manager has been established. If the queue manager is disconnected during the application, you can use the disconnect () function of the Queue Manager class, which does not have any parameters. If the application needs to reconnect the queue manager in the run, you can use the Connect (String QueueManagername, MQConnectOptions MQCNO) function, and the application can reset the queue manager name and connection option in this function.

Access queue: MA7P provides a processing queue of the MQQueue class, instances of this class can be established by connecting the objects MQQueueManager AccessQueue (String queueName, int openOptions) function to obtain the specific code as follows: MQQueueManager mqQMgr; MQQueue mqQueue; String queueName ; mqQMgr = new MQQueueManager (); mqQueue = mqQMgr.AccessQueue (queueName, MQC.MQOO_OUTPUT MQC.MQOO_FAIL_IF_QUIESING); accessQueue there is another overloaded function accessQueue (String queueName, int openOptions, String queueManagerName, String dynamicQueueName, String alternateUserId) This function provides functions such as dynamic queues, optional usernames. Send / Receive Message: The MA7P provides a message object MQMessage, using the PUT and GET methods of the MQQueue class, which can be implemented to / from the queue to / receive messages. The PUT function has the following two overload functions: PUT (MQMessage Message, MQPutMessageOptions PMO): Use this function application to customize send options; PUT (MQMESSAGE Message): Use this function to send messages to the queue to the queue using this function. The GET function has the following three overload functions: GET (MQMESSAGE Message, MQINT MAXMSGSIZE): This function allows applications to customize reception options and specify maximum message length; Get (MQMESSAGE MESSAGE, MQGTMESSAGEOptions GMO); Get (MQMESSAGE Message) The MQMessage object needs to be exhibited before use, for example: MQMessage MSG = new mqMessage (); mqqueue.get (msg); message processing: MQMessage class provides a large number of read / write functions to implement read / read / Write an operation, the specific function list, please refer to the reference provided by the MA7P package. The support of the transaction: The MQQueueManager class provides two functions for commit () and backout () to implement support for logical work units. However, the MQQueUemanager class does not provide a Begin function, so the function of the transaction manager cannot be implemented. If you don't make it very clear about the above programs, you only need to use the following code, you just need to copy the following: String Hostname = "192.168.0.22"; // server Ipstring Channel = "Dt_server_chl"; // server channel string qManager = "oa_qm"; // Queue Manager // Initializing environment variable mqenvironment.hostname = hostname; mqenvironment.channel = channel; mqenvironment.port = 1414; mqenvironment.port = 1414;

try {// constructor queue manager MQQueueManager qMgr = new MQQueueManager (qManager); int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT; MQQueue system_default_local_queue = qMgr.AccessQueue ( "LOCAL_DT_OA_INBOX", openOptions); // put message MQMessage hello_world = new MQMessage (); hello_world.WriteString ( "test message queue"); hello_world.Format = MQC.MQFMT_STRING; MQPutMessageOptions pmo = new MQPutMessageOptions (); // system_default_local_queue.Put (hello_world, pmo); // disconnect system_default_local_queue. CLOSE (); QMgr.disconnect ();} catch (mqexception ex) {messagebox.show (ex);

转载请注明原文地址:https://www.9cbs.com/read-109182.html

New Post(0)