Search code examples
sqlsql-server-2005stored-proceduresservice-broker

Service Broker conversations not closed (staying in CONVERSING state)


I'm noticing some conversations not getting closed, staying in CONVERSING state. The strange thing is, the queue is configured to process only 1 message at a time. In practice, however, there are 2 conversations in CONVERSING state, one which is really doing some work, and another one which seems to be stuck.

One thing I'm using is a single queue and service, which differs from the usual service broker implementations (making it more like a monologue instead of a dialog). I'm starting the activation SP with:

RECEIVE TOP(1)
    @Handle = conversation_handle,
    @MsgTypeName = message_type_name
FROM [//MyQueue]

IF (@@ROWCOUNT = 0)
    RETURN
ELSE IF ((@MsgTypeName is null) or (@Handle is null))
    RETURN
ELSE IF (@MsgTypeName != '//MyRequest')
    BEGIN
        END CONVERSATION @Handle
        RETURN
    END

Solution

  • Using "END CONVERSATION 'conversation handle' WITH CLEANUP;" is not wright way to end conversation.

    Service broker is designed for dialogs, not monolog conversations. That should be also the reason why there is 2 conversations (one for sending service and the other for receiving service- as services can reside in different databases/instances)

    You can create sending service, which is used for sending messages and receives "End Dialog" messages and ends dialog, the other which receives messages and does some processing with them + ends dialog when the work is done.