dbTalk Databases Forums  

Service Broker New Service Broker Application

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss Service Broker New Service Broker Application in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
newscorrespondent@charter.net
 
Posts: n/a

Default Service Broker New Service Broker Application - 09-10-2008 , 10:12 PM






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> )

Reply With Quote
  #2  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM






Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #3  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #4  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #5  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #6  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #7  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #8  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #9  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
  #10  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Service Broker New Service Broker Application - 09-11-2008 , 07:14 AM



Quote:
Should the code that checks for an 'End Dialog' message have an
ELSE
BEGIN BREAK;
END;
A common activated proc pattern is to wait for another message instead of
exiting immediately upon receipt of the EndDialog message. This way, SB
doesn't need to activate another proc instance when another message is
available in the queue. No problem exiting with smaller message volumes but
be sure to commit before exiting.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<newscorrespondent (AT) charter (DOT) net> wrote

Quote:
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> )


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.