是否有API從SQL Server存儲過程連接到Websphere MQ隊列並將消息放入隊列?如何在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
太好了,謝謝!這看起來好像是一個更好的方式,標記你的答案是正確的,而不是我自己的答案。 –