You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns a row for each queue monitor in the instance. A queue monitor manages activation for a queue.
24
-
24
+
Returns a row for each queue monitor in the instance. A queue monitor manages activation for a queue.
25
+
26
+
| Column name | Data type | Description |
27
+
| --- | --- | --- |
28
+
|`database_id`|**int**| Object identifier for the database that contains the queue that the monitor watches. Nullable. |
29
+
|`queue_id`|**int**| Object identifier for the queue that the monitor watches. Nullable. |
30
+
|`state`|**nvarchar(32)**| State of the monitor. Nullable. This value is one of the following options:<br /><br />`INACTIVE`<br />`NOTIFIED`<br />`RECEIVES_OCCURRING`|
31
+
|`last_empty_rowset_time`|**datetime**| Last time that a `RECEIVE` from the queue returned an empty result. Nullable. |
32
+
|`last_activated_time`|**datetime**| Last time that this queue monitor activated a stored procedure. Nullable. |
33
+
|`tasks_waiting`|**int**| Number of sessions that are currently waiting within a `RECEIVE` statement for this queue. Nullable.<br /><br />**Note:** This number includes any session executing a receive statement, regardless of whether the queue monitor started the session. This is for when you use `WAITFOR` together with `RECEIVE`. In other words, these tasks are waiting for messages to arrive on the queue. |
34
+
35
+
## Permissions
36
+
37
+
[!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and earlier versions require `VIEW SERVER STATE` permission on the server.
38
+
39
+
[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions require `VIEW SERVER PERFORMANCE STATE` permission on the server.
|**database_id**|**int**|Object identifier for the database that contains the queue that the monitor watches. NULLABLE.|
29
-
|**queue_id**|**int**|Object identifier for the queue that the monitor watches. NULLABLE.|
30
-
|**state**|**nvarchar(32)**|State of the monitor. NULLABLE. This is one of the following:<br /><br /> **INACTIVE**<br /><br /> **NOTIFIED**<br /><br /> **RECEIVES_OCCURRING**|
31
-
|**last_empty_rowset_time**|**datetime**|Last time that a RECEIVE from the queue returned an empty result. NULLABLE.|
32
-
|**last_activated_time**|**datetime**|Last time that this queue monitor activated a stored procedure. NULLABLE.|
33
-
|**tasks_waiting**|**int**|Number of sessions that are currently waiting within a RECEIVE statement for this queue. NULLABLE.<br /><br /> Note: This number includes any session executing a receive statement, regardless of whether the queue monitor started the session. This is if you use WAITFOR together with RECEIVE. Basically, these tasks are waiting for messages to arrive on the queue.|
34
-
35
-
## Permissions
36
-
Requires VIEW SERVER STATE permission on the server.
37
-
38
-
### Permissions for SQL Server 2022 and later
45
+
This scenario provides the current status of all message queues.
39
46
40
-
Requires VIEW SERVER PERFORMANCE STATE permission on the server.
47
+
```sql
48
+
SELECT DB_NAME() AS [Database_Name],
49
+
s.[name] AS [Service_Name],
50
+
sch.[name] AS [Schema_Name],
51
+
q.[name] AS [Queue_Name],
52
+
ISNULL(m.[state], N'Not available') AS [Queue_State],
53
+
m.tasks_waiting,
54
+
m.last_activated_time,
55
+
m.last_empty_rowset_time,
56
+
(SELECTCOUNT(1)
57
+
FROMsys.transmission_queueAS t6
58
+
WHEREt6.from_service_name= s.[name]) AS Tran_Message_Count
59
+
FROMsys.servicesAS s
60
+
INNER JOINsys.databasesAS d
61
+
ONd.database_id= DB_ID()
62
+
INNER JOINsys.service_queuesAS q
63
+
ONs.service_queue_id= q.[object_id]
64
+
INNER JOINsys.schemasAS sch
65
+
ON q.[schema_id] = sch.[schema_id]
66
+
LEFT OUTER JOINsys.dm_broker_queue_monitorsAS m
67
+
ON q.[object_id] =m.queue_id
68
+
ANDm.database_id=d.database_id;
69
+
```
41
70
42
-
## Examples
43
-
44
-
### A. Current status queue monitor
45
-
This scenario provides the current status of all message queues.
46
-
47
-
```
48
-
SELECT t1.name AS [Service_Name], t3.name AS [Schema_Name], t2.name AS [Queue_Name],
49
-
CASE WHEN t4.state IS NULL THEN 'Not available'
50
-
ELSE t4.state
51
-
END AS [Queue_State],
52
-
CASE WHEN t4.tasks_waiting IS NULL THEN '--'
53
-
ELSE CONVERT(VARCHAR, t4.tasks_waiting)
54
-
END AS tasks_waiting,
55
-
CASE WHEN t4.last_activated_time IS NULL THEN '--'
56
-
ELSE CONVERT(varchar, t4.last_activated_time)
57
-
END AS last_activated_time ,
58
-
CASE WHEN t4.last_empty_rowset_time IS NULL THEN '--'
59
-
ELSE CONVERT(varchar,t4.last_empty_rowset_time)
60
-
END AS last_empty_rowset_time,
61
-
(
62
-
SELECT COUNT(*)
63
-
FROM sys.transmission_queue t6
64
-
WHERE (t6.from_service_name = t1.name) ) AS [Tran_Message_Count]
65
-
FROM sys.services t1 INNER JOIN sys.service_queues t2
66
-
ON ( t1.service_queue_id = t2.object_id )
67
-
INNER JOIN sys.schemas t3 ON ( t2.schema_id = t3.schema_id )
68
-
LEFT OUTER JOIN sys.dm_broker_queue_monitors t4
69
-
ON ( t2.object_id = t4.queue_id AND t4.database_id = DB_ID() )
70
-
INNER JOIN sys.databases t5 ON ( t5.database_id = DB_ID() );
71
-
```
72
-
73
-
## See Also
74
-
[Dynamic Management Views and Functions (Transact-SQL)](~/relational-databases/system-dynamic-management-views/system-dynamic-management-views.md)
75
-
[Service Broker Related Dynamic Management Views (Transact-SQL)](../../relational-databases/system-dynamic-management-views/service-broker-related-dynamic-management-views-transact-sql.md)
0 commit comments