Hi,
I made a simple service broker code that is:
-- step 1: Enable Broker
use master
alter database AdventureWorks
set enable_broker
go
-- step 2: prepare
use AdventureWorks
go
create schema CustomerService
go
create schema EmailService
go
-- step 3: Message Type
create message type [//AdventureWorks/Sales/CustomerDetails]
validation = well_formed_xml
go
-- step 4: Contract
create contract [//AdventureWorks/Sales/SendCustomerDetails]
(
[//AdventureWorks/Sales/CustomerDetails] sent by initiator
)
go
-- step 5: Queue
create queue CustomerService.NewCustomerQueue
go
create queue EmailService.NewCustomerEmailQueue
go
-- step 6: Service
create service [//AdventureWorks/Sales/CustomerService]
on queue CustomerService.NewCustomerQueue
go
create service [//AdventureWorks/Sales/EmailService]
on queue EmailService.NewCustomerEmailQueue
(
[//AdventureWorks/Sales/SendCustomerDetails]
)
go
-- step 7:
create procedure CustomerService.proc_SendMessage
(
@firstName nvarchar(50)
,@lastName nvarchar(50)
,@emailAddress nvarchar(200)
)
as
-- sending a message
declare @message nvarchar(max)
set @message = nchar(0xFEFF)
+ '<Customer>'
+ '<CustomerName>' + @firstName + ' ' + @lastName + '</CustomerName>'
+ '<EmailAddress>' + @emailAddress + '</EmailAddress>'
+ '</Customer>'
declare @conversationHandle uniqueidentifier
begin dialog conversation @conversationHandle
from service [//AdventureWorks/Sales/CustomerService]
to service '//AdventureWorks/Sales/EmailService'
on contract [//AdventureWorks/Sales/SendCustomerDetails]
;send on conversation @conversationHandle
message type [//AdventureWorks/Sales/CustomerDetails]
(
@message
)
go
create procedure CustomerService.proc_ReceiveMessage
as
-- receiving a message
declare @conversationHandle uniqueidentifier, @messageTypeName nvarchar(256)
;receive top(1)
@conversationHandle = conversation_handle
,@messageTypeName = message_type_name
from CustomerService.NewCustomerQueue
if @@rowcount = 0
begin
print 'No further message found in CustomerService.NewCustomerQueue'
end
go
exec CustomerService.proc_SendMessage 'Bishoy','George','bishoy@bishoy.com'
exec CustomerService.proc_ReceiveMessage
--------------------------------------------------------------------------------------------------------------------------
Now the problem is:
when I execute the 2 procedures I receive:
(0 row(s) affected)
No further message found in CustomerService.NewCustomerQueue
Why doesn't the broker send the message?
Is there any needed preparing should I have done first?
Thank you and best regards.
Dan Sullivan - 04 Aug 2006 20:16 GMT
In this case there are three place you can look to see what happened, the sending queue, receiving queue and the sys.transmission_queue. One of those will probably have a message indicating what happened.
use AdventureWorks
SELECT * FROM CustomerService.NewCustomerQueue
SELECT * FROM EmailService.NewCustomerEmailQueue
SELECT * FROM sys.transmission_queue
I don't think the AdventureWorks database has a master key, which is needed in almost all cases by Service Broker. Try doing a
use AdventureWorks
CREATE MASTER PASSWORD ENCRYPTION BY PASSWORD = 'mya%%%Passw0rd'
Dan
Bishoy George - 06 Aug 2006 10:03 GMT
Thank you very much Dan.
You helped me very much.
Sorry for my late reply.
Thank you again.
Bishoy
> In this case there are three place you can look to see what happened, the
> sending queue, receiving queue and the sys.transmission_queue. One of
[quoted text clipped - 12 lines]
>
> Dan