
use SodaDB
go

-- 
-- diagnostic queries
-- 

-- Check inventory levels as its processing
SELECT * FROM inventory
go

-- turn activation off
ALTER QUEUE InvRequestQueue_L9A WITH ACTIVATION 
  (STATUS=OFF,
   PROCEDURE_NAME=decrement_inventory,
   MAX_QUEUE_READERS=5,
   EXECUTE AS SELF
  )
go

ALTER QUEUE InvRequestQueue_L9A WITH STATUS = ON

-- turn activation on again
ALTER QUEUE InvRequestQueue_L9A WITH ACTIVATION 
  (STATUS=ON,
   PROCEDURE_NAME=decrement_inventory,
   MAX_QUEUE_READERS=5,
   EXECUTE AS SELF
  )
go

select * from InvRequestQueue_L9A

select * from InvResponseQueue_L9A

SELECT * FROM inventory
go

select * from sys.transmission_queue

select * from sys.service_queues

select * from sys.conversation_endpoints

execute cleanup_all_endpoints

create procedure cleanup_all_endpoints
AS
BEGIN
DECLARE @h UNIQUEIDENTIFIER
DECLARE c CURSOR FOR
 SELECT conversation_handle FROM sys.conversation_endpoints
OPEN c
FETCH NEXT FROM c INTO @h
WHILE (@@FETCH_STATUS = 0)
BEGIN
  END CONVERSATION @h WITH CLEANUP
  FETCH NEXT FROM c INTO @h
END
CLOSE c
DEALLOCATE c
END

