将消息放在 IBM Websphere MQ 上
Putting Message on IBM Websphere MQ
我有一个应用程序需要将非常简单的消息放入远程队列。
使用的队列由第 3 方及其 IBM WebSphere MQ(版本 7.5)提供。
我尝试将 amqmdnet.dll
与下面的示例代码一起使用,但我知道我的服务器上应该安装一个 MQ 客户端来执行此操作。
所以我的问题是:
有没有办法在没有所有这些要求的情况下将消息放入队列中?像一个简单的 REST 或 SOAP 客户端?
我愿意使用不同的语言来实现这样的组件我只是不想在服务器(它的托管环境)上安装第 3 方应用程序
// ===========================================================================
// Licensed Materials - Property of IBM
// 5724-H72
// (c) Copyright IBM Corp. 2003, 2005
// ===========================================================================
using System;
using System.Collections;
using IBM.WMQ;
class MQSample
{
// The type of connection to use, this can be:-
// MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
// MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
// MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
// MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;
// Define the name of the queue manager to use (applies to all connections)
const String qManager = "your_Q_manager";
// Define the name of your host connection (applies to client connections only)
const String hostName = "your_hostname";
// Define the name of the channel to use (applies to client connections only)
const String channel = "your_channelname";
/// <summary>
/// Initialise the connection properties for the connection type requested
/// </summary>
/// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
static Hashtable init(String connectionType)
{
Hashtable connectionProperties = new Hashtable();
// Add the connection type
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
// Set up the rest of the connection properties, based on the
// connection type requested
switch(connectionType)
{
case MQC.TRANSPORT_MQSERIES_BINDINGS:
break;
case MQC.TRANSPORT_MQSERIES_CLIENT:
case MQC.TRANSPORT_MQSERIES_XACLIENT:
case MQC.TRANSPORT_MQSERIES_MANAGED:
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
break;
}
return connectionProperties;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
try
{
Hashtable connectionProperties = init(connectionType);
// Create a connection to the queue manager using the connection
// properties just defined
MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);
// Set up the options on the queue we want to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we want to open,and the open options
MQQueue system_default_local_queue =
qMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);
// Define a WebSphere MQ message, writing some text in UTF format
MQMessage hello_world = new MQMessage();
hello_world.WriteUTF("Hello World!");
// Specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
// same as MQPMO_DEFAULT
// Put the message on the queue
system_default_local_queue.Put(hello_world, pmo);
// Get the message back again
// First define a WebSphere MQ message buffer to receive the message
MQMessage retrievedMessage =new MQMessage();
retrievedMessage.MessageId =hello_world.MessageId;
// Set the get message options
MQGetMessageOptions gmo =new MQGetMessageOptions(); //accept the defaults
//same as MQGMO_DEFAULT
// Get the message off the queue
system_default_local_queue.Get(retrievedMessage,gmo);
// Prove we have the message by displaying the UTF message text
String msgText = retrievedMessage.ReadUTF();
Console.WriteLine("The message is: {0}", msgText);
// Close the queue
system_default_local_queue.Close();
// Disconnect from the queue manager
qMgr.Disconnect();
}
//If an error has occurred in the above,try to identify what went wrong.
//Was it a WebSphere MQ error?
catch (MQException ex)
{
Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
}
catch (System.Exception ex)
{
Console.WriteLine("A System error occurred: {0}", ex.ToString());
}
return 0;
}//end of start
}//end of sample
不是选择 MQC.TRANSPORT_MQSERIES_CLIENT
这会导致 amqmdnet.dll
在非托管模式下运行并依赖于其他非 .NET dll,您可以 select MQC.TRANSPORT_MQSERIES_MANAGED
使其在托管模式下运行,这意味着它不需要任何其他 dll 即可运行。
在 MQ v7.5 中,即使在托管模式下,您也不能单独使用 amqmdnet.dll
,在该版本中 IBM 不支持此配置。在 IBM MQ v8 和更高版本中,IBM 确实支持单独使用 amqmdnet.dll
。您可以从以下链接之一下载 MQ v8 或 MQ v9 可再发行客户端。只需从 zip 文件中找到 amqmdnet.dll
并使用它。
MQ 完全向后兼容,从更高版本的客户端连接到 MQ 7.5 队列管理器应该不是问题。另请注意,MQ v7.5 将于 2018 年 4 月 30 日停止支持,为保持 IBM 的支持,第 3 方将需要升级或支付额外费用以获得扩展支持。
我有一个应用程序需要将非常简单的消息放入远程队列。 使用的队列由第 3 方及其 IBM WebSphere MQ(版本 7.5)提供。
我尝试将 amqmdnet.dll
与下面的示例代码一起使用,但我知道我的服务器上应该安装一个 MQ 客户端来执行此操作。
所以我的问题是: 有没有办法在没有所有这些要求的情况下将消息放入队列中?像一个简单的 REST 或 SOAP 客户端? 我愿意使用不同的语言来实现这样的组件我只是不想在服务器(它的托管环境)上安装第 3 方应用程序
// ===========================================================================
// Licensed Materials - Property of IBM
// 5724-H72
// (c) Copyright IBM Corp. 2003, 2005
// ===========================================================================
using System;
using System.Collections;
using IBM.WMQ;
class MQSample
{
// The type of connection to use, this can be:-
// MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
// MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
// MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
// MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;
// Define the name of the queue manager to use (applies to all connections)
const String qManager = "your_Q_manager";
// Define the name of your host connection (applies to client connections only)
const String hostName = "your_hostname";
// Define the name of the channel to use (applies to client connections only)
const String channel = "your_channelname";
/// <summary>
/// Initialise the connection properties for the connection type requested
/// </summary>
/// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
static Hashtable init(String connectionType)
{
Hashtable connectionProperties = new Hashtable();
// Add the connection type
connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
// Set up the rest of the connection properties, based on the
// connection type requested
switch(connectionType)
{
case MQC.TRANSPORT_MQSERIES_BINDINGS:
break;
case MQC.TRANSPORT_MQSERIES_CLIENT:
case MQC.TRANSPORT_MQSERIES_XACLIENT:
case MQC.TRANSPORT_MQSERIES_MANAGED:
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
break;
}
return connectionProperties;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
try
{
Hashtable connectionProperties = init(connectionType);
// Create a connection to the queue manager using the connection
// properties just defined
MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);
// Set up the options on the queue we want to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we want to open,and the open options
MQQueue system_default_local_queue =
qMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);
// Define a WebSphere MQ message, writing some text in UTF format
MQMessage hello_world = new MQMessage();
hello_world.WriteUTF("Hello World!");
// Specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
// same as MQPMO_DEFAULT
// Put the message on the queue
system_default_local_queue.Put(hello_world, pmo);
// Get the message back again
// First define a WebSphere MQ message buffer to receive the message
MQMessage retrievedMessage =new MQMessage();
retrievedMessage.MessageId =hello_world.MessageId;
// Set the get message options
MQGetMessageOptions gmo =new MQGetMessageOptions(); //accept the defaults
//same as MQGMO_DEFAULT
// Get the message off the queue
system_default_local_queue.Get(retrievedMessage,gmo);
// Prove we have the message by displaying the UTF message text
String msgText = retrievedMessage.ReadUTF();
Console.WriteLine("The message is: {0}", msgText);
// Close the queue
system_default_local_queue.Close();
// Disconnect from the queue manager
qMgr.Disconnect();
}
//If an error has occurred in the above,try to identify what went wrong.
//Was it a WebSphere MQ error?
catch (MQException ex)
{
Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
}
catch (System.Exception ex)
{
Console.WriteLine("A System error occurred: {0}", ex.ToString());
}
return 0;
}//end of start
}//end of sample
不是选择 MQC.TRANSPORT_MQSERIES_CLIENT
这会导致 amqmdnet.dll
在非托管模式下运行并依赖于其他非 .NET dll,您可以 select MQC.TRANSPORT_MQSERIES_MANAGED
使其在托管模式下运行,这意味着它不需要任何其他 dll 即可运行。
在 MQ v7.5 中,即使在托管模式下,您也不能单独使用 amqmdnet.dll
,在该版本中 IBM 不支持此配置。在 IBM MQ v8 和更高版本中,IBM 确实支持单独使用 amqmdnet.dll
。您可以从以下链接之一下载 MQ v8 或 MQ v9 可再发行客户端。只需从 zip 文件中找到 amqmdnet.dll
并使用它。
MQ 完全向后兼容,从更高版本的客户端连接到 MQ 7.5 队列管理器应该不是问题。另请注意,MQ v7.5 将于 2018 年 4 月 30 日停止支持,为保持 IBM 的支持,第 3 方将需要升级或支付额外费用以获得扩展支持。