我的系统中安装了数据库SQL Server 2012
和activemq。我可以使用java程序向activemq发送消息并从activemq接收消息。我编写了两个名为MessageProducer和MessageConsumer的java程序,分别用于发送和接收。现在我想从数据库发送消息到activemq,任何人都可以帮我做这个吗?
注意:我可以在同一个数据库中发送和接收消息,我是通过以下link完成的。但它在同一个数据库中甚至不在不同的SQL Server之间。我想我应该使用endpoints
进行服务器 - 服务器通信,我试过但我不知道如何使用。
编辑我的问题感觉很舒服。
感谢您花时间看我的问题。
编辑:经过一点点搜索,我做了类似的事情,从数据库发送消息
--Create a Service Broker endpoint
USE master;
GO
IF EXISTS (SELECT * FROM sys.endpoints
WHERE name = N'InstInitiatorEndpoint')
DROP ENDPOINT InstInitiatorEndpoint;
GO
CREATE ENDPOINT InstInitiatorEndpoint
STATE = STARTED
AS TCP ( LISTENER_PORT = 61616 )
FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS );
GO
--Create the Initiator database, master key, and user
USE master;
GO
IF EXISTS (SELECT * FROM sys.databases
WHERE name = N'InstInitiatorDB')
DROP DATABASE InstInitiatorDB;
GO
CREATE DATABASE InstInitiatorDB;
GO
USE InstInitiatorDB;
GO
CREATE MASTER KEY
ENCRYPTION BY PASSWORD = N'<EnterStrongPassword2Here>';
GO
CREATE USER InitiatorUser WITHOUT LOGIN;
GO
--Create the Initiator certificate
CREATE CERTIFICATE InstInitiatorCertificate
AUTHORIZATION InitiatorUser
WITH SUBJECT = N'Initiator Certificate',
EXPIRY_DATE = N'12/31/2013';
BACKUP CERTIFICATE InstInitiatorCertificate
TO FILE =
N'I:\MsSql\QueryNotification\InstTargetCertificate.cer';
GO
--Create the message types
CREATE MESSAGE TYPE [//BothDB/2InstSample/RequestMessage]
VALIDATION = WELL_FORMED_XML;
GO
--Create the contract
CREATE CONTRACT [//BothDB/2InstSample/SimpleContract]
( [//BothDB/2InstSample/RequestMessage] SENT BY INITIATOR
);
GO
--Create the Initiator queue and service
CREATE QUEUE InstInitiatorQueue;
CREATE SERVICE [//InstDB/2InstSample/InitiatorService]
AUTHORIZATION InitiatorUser
ON QUEUE InstInitiatorQueue;
GO
--Create routes
DECLARE @Cmd NVARCHAR(4000);
SET @Cmd = N'USE msdb
CREATE ROUTE InstInitiatorRoute
WITH SERVICE_NAME =
N''//InstDB/2InstSample/InitiatorService'',
ADDRESS = N''TCP://localhost:61616''';
EXEC (@Cmd);
GO
activemq tcp端口为tcp//localhost:61616
,我的sql server运行端口为1433
。
在此之后我该怎么做才能从sql server发送消息并在activemq的队列中看到消息?