/*
  Setup script for server 2 database 2 for SSB sample communicating
  between two remote servers

  This script to receives a message on the queue from the remote service
  and sends a message back.

  Any questions etc.: nielsb@develop.com

*/

--Step 1

use [rem_ssb2];
go

--check that we have a message in the queue
--if you have followed the script up until here
--there should be a message in the queue

SELECT * from q2;
go

----so a message is in the queue
----read off the message, send a message back;
----uncomment from here to go, and execute

--DECLARE @m xml; --the received message
--DECLARE @h uniqueidentifier; -- conversation handle
--
--receive top(1) @m = message_body,
--              @h = conversation_handle
--from q2
--
----select out the message
--select @m;
--
--DECLARE @msg xml; --return msg
--SET @msg = '<worldo/>';
--SEND ON CONVERSATION @h
--MESSAGE TYPE [recmsg]
--(@msg);
--go

--Step 2

--check if the transmission_status column in sys.transmission_queue
--has any messages, if so something is not entirely correct
--uncomment from here to go, and execute
--DECLARE @txmsg varchar(max)
--select top(1) @txmsg = transmission_status
--from sys.transmission_queue
--if @txmsg <> ''
--  begin
--    raiserror(@txmsg, 16, 1)
--  end

--Step 3
--if everything is now OK, you can end the conversation
--uncomment from here to go, and execute
--declare @h uniqueidentifier
--select top(1) @h = conversation_handle
--from sys.conversation_endpoints
--
--end conversation @h
--go

--go now back to server 1 and Step 2 in 4_recmsg_server2_db.sql
--and finish

