0

有带有 SQL Server 实例的服务器 A 和 B。有通过 TRANSPORT 的路线创建的服务。消息被成功接收。我正在尝试在 B 上创建内部激活,但队列停止。我究竟做错了什么?固定的。对于从 A 发送到 B 的每条消息,返回 5 个副本。

服务器 A

      USE master
    GO

    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'PAROLPAROL123'

    CREATE CERTIFICATE [GA_SERVER]
    WITH SUBJECT = 'GA_SERVER';
    GO

    CREATE ENDPOINT BROKER
       STATE=STARTED
       AS TCP (LISTENER_PORT = 4022)
       FOR SERVICE_BROKER 
       (
         AUTHENTICATION = CERTIFICATE [GA_SERVER]
       );

    GRANT CONNECT ON ENDPOINT::BROKER TO [PUBLIC];
    GO

    CREATE DATABASE DB_A
    GO

    ALTER DATABASE DB_A
     SET ENABLE_BROKER
     WITH ROLLBACK IMMEDIATE;

    GO

    USE DB_A;
    CREATE MESSAGE TYPE RequestMT
     validation=NONE;

    CREATE MESSAGE TYPE ResponseMT 
     validation=NONE;

    CREATE CONTRACT GAContract
    (
      RequestMT 
       SENT BY INITIATOR,
      ResponseMT
       SENT BY TARGET
    );

    CREATE QUEUE GAQueue
     WITH status = ON;

    CREATE SERVICE [tcp://10.10.100.56:4022/GAservice]
     ON QUEUE GAQueue (GAContract)
    GO

    GRANT SEND ON SERVICE::[tcp://10.10.100.56:4022/GAservice] TO [PUBLIC]
    CREATE ROUTE transport WITH ADDRESS = 'TRANSPORT';

    GO
CREATE TABLE [dbo.t1](
    [mes] [nvarchar](max) NULL
) ON [PRIMARY];

GO

CREATE PROCEDURE ActivProcA
AS
BEGIN
SET NOCOUNT ON
  DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
  DECLARE @RecvReqMsg NVARCHAR(1000);
  DECLARE @RecvReqMsgName sysname;

BEGIN TRANSACTION;  
WHILE (1=1)
BEGIN

WAITFOR
( RECEIVE TOP(1)
        @RecvReqDlgHandle = conversation_handle,
        @RecvReqMsg = message_body,
        @RecvReqMsgName = message_type_name
    FROM GAQueue
), TIMEOUT 5000;
    IF (@@ROWCOUNT = 0)
    BEGIN
      ROLLBACK TRANSACTION;
--      END CONVERSATION @RecvReqDlgHandle;
      BREAK;
    END

    IF @RecvReqMsgName =
       N'ResponseMT'
    BEGIN
     INSERT INTO [dbo.t1] (mes) VALUES (N'back to A from B ('+ CAST(CURRENT_TIMESTAMP AS NVARCHAR)+N'):'+@RecvReqMsg);  
    END 
     ELSE   
      END CONVERSATION @RecvReqDlgHandle;   
    COMMIT TRANSACTION;     
SET NOCOUNT OFF;
END;
END;  

GO

ALTER QUEUE GAQueue
    WITH 
    STATUS = ON,
    ACTIVATION
    ( STATUS = ON,
      PROCEDURE_NAME = ActivProcA,
      MAX_QUEUE_READERS = 10,
      EXECUTE AS SELF 
    );
GO

服务器 B

USE MASTER
GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'PAROLPAROL123'

CREATE CERTIFICATE [GOS_SERVER]
WITH SUBJECT = 'GOS_SERVER';
GO

CREATE ENDPOINT BROKER
   STATE=STARTED
   AS TCP (LISTENER_PORT = 4022)
   FOR SERVICE_BROKER 
   (
     AUTHENTICATION = CERTIFICATE [GOS_SERVER],
   );

GRANT CONNECT ON ENDPOINT::BROKER TO [PUBLIC];
GO

CREATE DATABASE DB_B_1
GO

ALTER DATABASE DB_B_1
 SET ENABLE_BROKER
 WITH ROLLBACK IMMEDIATE;
GO

USE DB_B_1;
CREATE MESSAGE TYPE RequestMT
 validation=NONE;

CREATE MESSAGE TYPE ResponseMT 
 validation=NONE;

CREATE CONTRACT GAContract
(
  RequestMT 
   SENT BY INITIATOR,
  ResponseMT
   SENT BY TARGET
);

CREATE QUEUE GAQueue
 WITH status = OFF; 

GO

CREATE SERVICE [tcp://10.10.100.78:4022/GOS_DB_B_1_service]
 ON QUEUE GAQueue (GAContract)
GO

GRANT SEND ON SERVICE::[tcp://10.10.100.78:4022/GOS_DB_B_1_service] TO [PUBLIC]

CREATE ROUTE transport WITH ADDRESS = 'TRANSPORT';

GO

CREATE TABLE [dbo.t1](
    [mes] [nvarchar](max) NULL
) ON [PRIMARY];
GO

CREATE PROCEDURE ActivProcB
AS
 BEGIN
  SET NOCOUNT ON; 
  DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
  DECLARE @RecvReqMsg NVARCHAR(100);
  DECLARE @RecvReqMsgName sysname;

  WHILE (1=1)
  BEGIN
    BEGIN TRANSACTION;

    WAITFOR
    ( RECEIVE TOP(1)
        @RecvReqDlgHandle = conversation_handle,
        @RecvReqMsg = message_body,
        @RecvReqMsgName = message_type_name
      FROM GAQueue
    ), TIMEOUT 5000;

    IF (@@ROWCOUNT = 0)
    BEGIN
      ROLLBACK TRANSACTION;
      BREAK;
    END

    IF @RecvReqMsgName =
       N'RequestMT'
    BEGIN
        INSERT INTO [dbo.t1] (mes) VALUES (N'('+ CAST(CURRENT_TIMESTAMP AS NVARCHAR)+N'):'+@RecvReqMsg);             
        DECLARE @Msg NVARCHAR(100);
        DECLARE @I INT;
        SET @I = 1;
        WHILE @I<6 
        BEGIN
         SET @Msg = N'<MsgFromB1>'+CAST (@I AS NVARCHAR(1))+N' ('+CAST(CURRENT_TIMESTAMP AS NVARCHAR)+N')</MsgFromB1>';
         SEND ON CONVERSATION @RecvReqDlgHandle
               MESSAGE TYPE 
                ResponseMT
               (@Msg);       
         SET @I = @I+1;     
        END                 
    END;      
    COMMIT TRANSACTION;     
  END

SET NOCOUNT OFF;  
END;
GO

ALTER QUEUE GAQueue
    WITH 
     STATUS = ON,
     ACTIVATION
    ( STATUS = ON,
      PROCEDURE_NAME = ActivProcB,
      MAX_QUEUE_READERS = 10,
      EXECUTE AS SELF
    );
GO

服务器 A

USE DB_A

DECLARE @ConversationHandle UNIQUEIDENTIFIER;
DECLARE @RequestMsg NVARCHAR(4000);

BEGIN TRANSACTION

BEGIN DIALOG @ConversationHandle
 FROM SERVICE [tcp://10.10.100.56:4022/GAservice]
 TO SERVICE 'tcp://10.10.100.78:4022/GOS_DB_B_1_service'
 ON CONTRACT GAContract
 WITH ENCRYPTION = OFF;

 SELECT @RequestMsg =
       N'<RequestMsg>test1</RequestMsg>';

SEND 
 ON CONVERSATION @ConversationHandle
     MESSAGE TYPE RequestMT
  (@RequestMsg);

COMMIT TRANSACTION;

GO
4

1 回答 1

1

我正在尝试在 B 上创建内部激活,但队列停止

这很可能是启动了有毒消息检测。这意味着您激活的过程正在引发异常并导致回滚。发生这种情况时,过程的输出(包括错误消息)会记录到 ERRORLOG 中。那是你需要看的地方。

您还可以尝试通过禁用激活并从查询窗口手动调用该过程来排除该过程的故障。这样,您将直接看到任何错误消息/异常。要在与激活过程相同的上下文中执行,请EXECUTE AS USER = 'dbo'在调用过程之前发出 an。

请参阅对激活存储过程进行故障排除

于 2013-07-24T20:57:27.517 回答