BEGIN CONVERSATION TIMER (Transact-SQL)
Applies To: SQL Server 2014, SQL Server 2016 Preview
Starts a timer. When the time-out expires, Service Broker puts a message of type http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer on the local queue for the conversation.
Applies to: SQL Server (SQL Server 2008 through current version).
- BEGIN CONVERSATION TIMER (conversation_handle)
Specifies the conversation to time. The conversation_handle must be of type uniqueidentifier.
Specifies, in seconds, the amount of time to wait before putting the message on the queue.
A conversation timer provides a way for an application to receive a message on a conversation after a specific amount of time. Calling BEGIN CONVERSATION TIMER on a conversation before the timer has expired sets the timeout to the new value. Unlike the conversation lifetime, each side of the conversation has an independent conversation timer. The DialogTimer message arrives on the local queue without affecting the remote side of the conversation. Therefore, an application can use a timer message for any purpose.
For example, you can use the conversation timer to keep an application from waiting too long for an overdue response. If you expect the application to complete a dialog in 30 seconds, you might set the conversation timer for that dialog to 60 seconds (30 seconds plus a 30-second grace period). If the dialog is still open after 60 seconds, the application receives a time-out message on the queue for that dialog.
Alternatively, an application can use a conversation timer to request activation at a particular time. For example, you might create a service that reports the number of active connections every few minutes, or a service that reports the number of open purchase orders every evening. The service sets a conversation timer to expire at the desired time; when the timer expires, Service Broker sends a DialogTimer message. The DialogTimer message causes Service Broker to start the activation stored procedure for the queue. The stored procedure sends a message to the remote service and restarts the conversation timer.
BEGIN CONVERSATION TIMER is not valid in a user-defined function.
Permission for setting a conversation timer defaults to users that have SEND permissions on the service for the conversation, members of the sysadmin fixed server role, and members of the db_owner fixed database role.
The following example sets a two-minute time-out on the dialog identified by @dialog_handle.
-- @dialog_handle is of type uniqueidentifier and -- contains a valid conversation handle. BEGIN CONVERSATION TIMER (@dialog_handle) TIMEOUT = 120 ;