如何在SQL Server sp上的Websphere MQ Queue上放置消息?
是否有API从SQL Server存储过程连接到Websphere MQ队列并将消息放入队列?如何在SQL Server sp上的Websphere MQ Queue上放置消息?
如果不是,最好的方法是什么?
我能想到的最简单的方法是,将信息写入文件,然后使用rfhutil将消息导出到队列中。这需要人工干预。另一种选择是使用JMS和JDBC编写简单的Java应用程序。
我打算使用的解决方案是编写CLR存储过程并将其部署到SQL Server上。
在CLR存储过程中,我将使用MQ .NET API。
更新:我创建了一个存储过程使用下面的代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using IBM.WMQ;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static int MQStoredProc(String queueManager, String queueName, String messageText)
{
//MQEnvironment.Hostname = "localhost";
//MQEnvironment.Port = 1414;
//MQEnvironment.Channel = "SYSTEM.DEF.SVRCONN";
MQQueueManager mqQMgr = null; // MQQueueManager instance
MQQueue mqQueue = null; // MQQueue instance
try
{
mqQMgr = new MQQueueManager(queueManager);
mqQueue = mqQMgr.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING); // open queue for output but not if MQM stopping
if (messageText.Length > 0)
{
// put the next message to the queue
MQMessage mqMsg = new MQMessage();
mqMsg.WriteString(messageText);
mqMsg.Format = MQC.MQFMT_STRING;
MQPutMessageOptions mqPutMsgOpts = new MQPutMessageOptions();
mqQueue.Put(mqMsg, mqPutMsgOpts);
}
return 0;
}
catch (MQException mqe)
{
return ((int)mqe.Reason);
}
finally
{
if (mqQueue != null)
mqQueue.Close();
if (mqQMgr != null)
mqQMgr.Disconnect();
}
}
};
这不是生产做好准备,但成功地将在队列管理器在同一台服务器中绑定的SQL服务器上运行的消息模式。
Neal,你是怎么在SqlServer中注册amqmdnet.dll的? 我有这个错误: 大会'amqmdnet'无法安装,因为现有的政策会阻止它被使用。 的代码是: 从创建装配amqmdnet “C:\ MSSQL \装配\ amqmdnet.dll” 与PERMISSION_SET =不安全 – Boogier
.NET CLR方法也是我的建议。我很想看到代码的一个例子,我从来没有尝试过!我应该工作。
我尝试了CLR的方法,它的效果很好,添加示例代码,我的答案,如果你想查看。 –
您是否能够在prod env中进行部署,并且您是否有任何打嗝? – ygoku
太好了,谢谢!这看起来好像是一个更好的方式,标记你的答案是正确的,而不是我自己的答案。 –