![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#3
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#4
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#5
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#6
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#7
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#8
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#9
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
#10
| |||
| |||
|
|
Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; |
|
In Sql Server Management Studio when I right click on the Service Broker and select New Service Broker Application the code that it generates (included below) looks like it has an error to me. Should the code that checks for an 'End Dialog' message have an ELSE BEGIN BREAK; END; or why do the loop again? Thanks Tom -- ================================================== ========== -- Create Request Response Application with Activation Template -- ================================================== ========== -- Create the stored procedure if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[<ssb-proc-name, sysname, test_proc>]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[<ssb-proc-name, sysname, test_proc>] GO SET ANSI_NULLS OFF go SET QUOTED_IDENTIFIER OFF go CREATE PROCEDURE [dbo].[<ssb-proc-name, sysname, test_proc>] AS declare @message_body nvarchar(MAX) declare @message_type int declare @dialog uniqueidentifier while (1 = 1) begin begin transaction -- Receive the next available message from the queue WAITFOR ( RECEIVE top(1) -- just handle one message at a time @message_type=message_type_id, --the type of message received @message_body=message_body, -- the message contents @dialog = conversation_handle -- the identifier of the dialog this message was received on FROM <queue-name, sysname, test_queue ), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away -- If we didn't get anything, bail out if (@@ROWCOUNT = 0) BEGIN Rollback Transaction BREAK END -- Check for the End Dialog message. If (@message_type <> 2) -- End dialog message BEGIN -- Send the message back to the sender. SEND ON CONVERSATION @dialog -- send it back on the dialog we received the message on MESSAGE TYPE [<Response-message-type, sysname, test_msg_resp>] -- Must always supply a message type (@message_body); -- the message contents (a varbinary(MAX) blob END -- Commit the transaction. At any point before this, we could roll -- back - the received message would be back on the queue and the response -- wouldn't be sent. commit transaction end go -- Create the required meta-data CREATE MESSAGE TYPE <Request-message-type, sysname, test_msg_req VALIDATION = NONE CREATE MESSAGE TYPE <Response-message-type, sysname, test_msg_resp VALIDATION = NONE CREATE CONTRACT <contract-name, sysname, test_contract ( <Request-message-type, sysname, test_msg_req> SENT BY INITIATOR, Response-message-type, sysname, test_msg_resp> SENT BY TARGET) CREATE QUEUE <queue-name, sysname, test_queue WITH ACTIVATION ( PROCEDURE_NAME = [<ssb-proc-name, sysname, test_proc>] , MAX_QUEUE_READERS = 5, EXECUTE AS SELF ) CREATE SERVICE [<service-name, sysname, test_service>] ON QUEUE <queue-name, sysname, test_queue ALTER SERVICE [<service-name, sysname, test_service>] ( ADD CONTRACT <contract-name, sysname, test_contract> ) |
![]() |
| Thread Tools | |
| Display Modes | |
| |