我正在配置一个简单的服务代理实现。在本地,我们使用 SQL Server 2008 Express,一切正常。一旦代码在我们的生产服务器(SQL SERVER 2005)上运行,消息就会卡在接收者队列中。以下代码不完整,但说明了队列和服务的基本配置方式:
-- Create message type to validate the content of a message
CREATE MESSAGE TYPE MyMessageType VALIDATION = NONE;
-- Create contract to validate what direction messages can be sent in a conversation.
CREATE CONTRACT MyContract
(
MyMessageType SENT BY INITIATOR
)
-- The receiver queue will process each message using the 'spProcessMessage' stored procedure
CREATE QUEUE [MyReceiverQueue];
ALTER QUEUE [MyReceiverQueue] WITH ACTIVATION
(
STATUS = ON,
MAX_QUEUE_READERS = 1,
PROCEDURE_NAME = spProcessMessage,
EXECUTE AS SELF
);
-- The receiver service processes the incoming messages and passes them to the ReceiverQueue.
CREATE SERVICE [MyReceiverService] ON QUEUE [MyReceiverQueue]([MyContract]);
-- Queue and service to send the message from
CREATE QUEUE [MySenderQueue];
CREATE SERVICE [MySenderService] ON QUEUE [MySenderQueue];
安装服务后,会以这种方式触发消息:
-- Send a message to the receiver queue
DECLARE @MessageBody XML
SET @MessageBody = '';
DECLARE @Handle UNIQUEIDENTIFIER;
BEGIN DIALOG CONVERSATION @Handle
FROM SERVICE [MySenderService]
TO SERVICE 'MyReceiverQueue'
ON CONTRACT [MyContract]
WITH ENCRYPTION = OFF;
SEND ON CONVERSATION @Handle
MESSAGE TYPE [MyMessageType](@MessageBody);
所有消息都卡在“MyReceiverQueue”中。如果我手动执行“spProcessMessage”,则消息会正常处理。
更多细节:
- sys.transmission_queue为空
- sys.conversation_endpoints声明两个服务都是“正在转换”
- 启用了代理,并且将数据库配置为与 SQL 2005 兼容
任何想法为什么不自动处理这些消息?
非常感谢您的时间。
--
好的,在玩了一会儿之后,我得到了ssbdiagnose工作。正如 Remus 所说,它位于:C:\Program Files\Microsoft SQL Server\100\Tools\Binn。我以这种方式使其在本地工作:
ssbdiagnose -E -S "JDECUPER\SQLEXPRESS" -d mydb CONFIGURATION FROM SERVICE MySenderService TO SERVICE MyReceiverService ON CONTRACT MyContract
然后,我在我们的生产服务器上试了一下:
ssbdiagnose -XML -U loginID -P pwd -S "machine's IP" -d mydb CONFIGURATION FROM SERVICE MySenderService TO SERVICE MyReceiverService ON CONTRACT MyContract > C:\testBrokerService.xml
检测到的第一个错误:
Service Broker GUID is identical to that of database Pandilla on server 200.57.141.193
服务器上的另一个数据库具有与服务代理相同的 GUID。我只需要重新生成 GUID:
ALTER DATABASE [myotherdb] SET NEW_BROKER;
第二个错误与用户执行存储过程的权限有关:
The EXECUTE AS for the user dbo specified for activation on queue dbo.AlbumGanadoresQueue cannot be impersonated due to an exception
升级这些权限后,一切都开始正常工作。
非常感谢 Remus 为我指明了正确的方向。我有点长,但我希望细节能帮助其他开发人员。