首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将来自SQL Server sp的消息放到Websphere MQ队列中?

如何将来自SQL Server sp的消息放到Websphere MQ队列中?
EN

Stack Overflow用户
提问于 2011-09-21 20:26:26
回答 4查看 8K关注 0票数 4

是否有API可以从SQL Server存储过程连接到Websphere MQ队列并将消息放到队列中?

如果没有,实现这一目标的最好方法是什么?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-26 17:07:14

有一个比that..Check更简单的解决方案。

http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fbc34040_.htm

票数 1
EN

Stack Overflow用户

发布于 2011-09-22 17:40:27

为此,我将使用的解决方案是编写一个CLR存储过程并将其部署到SQL Server上。

在CLR存储过程中,我将使用MQ .NET。

更新:我使用以下代码创建了一个存储的进程:

代码语言:javascript
复制
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服务器相同的服务器上运行的队列管理器上成功插入了消息。

票数 4
EN

Stack Overflow用户

发布于 2011-09-22 14:58:06

我能想到的最简单的方法是,将信息写入一个文件,然后使用rfhutil将消息导出到队列中。这将需要手动干预。另一种选择是使用JMS和JDBC编写一个简单的java应用程序。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7499696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档