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
Copy file name to clipboardExpand all lines: docs/database-engine/service-broker/handling-poison-messages.md
+5-8Lines changed: 5 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,13 +36,11 @@ Consider the following questions when you decide how the application handles a p
36
36
37
37
## Example: Detecting a Poison Message
38
38
39
-
40
-
41
39
This Transact-SQL example shows a simple, stateless service that includes logic for handling poison messages. Before the stored procedure receives a message, the procedure saves the transaction. When the procedure cannot process a message, the procedure rolls the transaction back to the save point. The partial rollback returns the message to the queue while continuing to hold a lock on the conversation group for the message. Because the program continues to hold the conversation group lock, the program can update a table that maintains a list of failed messages without risk that another queue reader might process the message.
42
40
43
41
The following example defines the activation stored procedure for the application:
44
42
45
-
```
43
+
```sql
46
44
CREATE PROCEDURE ProcessExpenseReport
47
45
AS
48
46
BEGIN
@@ -116,7 +114,7 @@ The following example defines the activation stored procedure for the applicatio
116
114
117
115
The stored procedure TrackMessage tracks the number of times that a message has failed. When the message has not failed before, the procedure inserts a new counter for the message into the table ExpenseServiceFailedMessages. Otherwise, the procedure checks the counter for the number of times that the message failed. The procedure increments the counter when the counter is less than a predefined number. When the counter is greater than the predefined number, the procedure ends the conversation with an error and removes the counter for the conversation from the table.
118
116
119
-
```
117
+
```sql
120
118
CREATE PROCEDURE TrackMessage
121
119
@conversationHandle uniqueidentifier
122
120
AS
@@ -154,7 +152,7 @@ The stored procedure TrackMessage tracks the number of times that a message has
154
152
155
153
The definition of table ExpenseServiceFailedMessages simply contains a conversation_handle column and a count column, as shown in the following sample:
156
154
157
-
```
155
+
```sql
158
156
CREATETABLEExpenseServiceFailedMessages (
159
157
conversation_handle uniqueidentifier PRIMARY KEY,
160
158
count smallint
@@ -163,7 +161,7 @@ The definition of table ExpenseServiceFailedMessages simply contains a conversat
163
161
164
162
The procedure ClearMessageTracking deletes the counter for a conversation from the table ExpenseServiceFailedMessages, as shown in the following sample:
165
163
166
-
```
164
+
```sql
167
165
CREATE PROCEDURE ClearMessageTracking
168
166
@conversationHandle uniqueidentifier
169
167
AS
@@ -196,5 +194,4 @@ If you believe that the processing you perform on the message might cause a tran
0 commit comments