我正在配置一个简单的服务代理实现。在本地,我们使用SQL Server 2008 Express,一切正常。一旦代码在我们的生产服务器上运行(SQL SERVER 2005),消息就会卡在接收器队列中。 followind代码不完整,但说明了基本配置队列和服务的方式:
-- 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 表明这两项服务都是'转换'
- 启用代理并将DB配置为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让我指出正确的方向。我有点长,但我希望细节能帮助其他开发者。
答案 0 :(得分:8)
首先阅读我网站上的Troubleshooting Dialogs指南,然后按照步骤进行操作,直至找到可能的问题。
其次,如果您可以访问SQL 2008部署,请从中运行ssbdiagnose工具。虽然是SQL 2008的一部分,但完全能够诊断SQL 2005。这是首选方法, if 您可以访问SQL 2k8部署。