问题
I have SQL Service Broker set up between two servers over network and it is working alright. I'm implementing error processing at the moment. I have stored procedures attached to both queues to process messages.
In the cases when sending a message fails, such as when attempting to send malformed XML, the message stays in the sender queue. The transmission status is
Service Broker received an error message on this conversation. Service Broker will not transmit the message; it will be held until the application ends the conversation.
When querying the queue (stored procedures turned off for debugging) with select * from sys.transmission_queue
, the is_conversation_error
and is_end_of_dialog
fields are 0
and message_type_name
is the same I used when sending, instead of the usual error type.
Is there a way to recognize such messages in the queue? My automatic sender queue is processing them as normal messages at the moment.
回答1:
A malformed XML error will send back to your dialog an error message. This will be enqueued in your application queue and your app has to deal with it, as it must deal with any error message in its queue.
Note that you are confusing the sender queue with the transmission_queue
. The sender queue is an ordinary queue created with CREATE QUEUE
, and is the queue associated with your sending service. The error message I'm talking about is deposited in your sender queue and you can retrieve it with RECEIVE
. The transmission_queue
is an internal table owned by system that contains messages pending delivery. You cannot RECEIVE
from the transmission_queue
.
Judging from your post I guess your application is missing handling of messages in the sender queue. Even if your logical message flow is always from service 'A' to service 'B', you must have message handling for 'A' service queue as well. If nothing else, it is necessary for handling errors.
来源:https://stackoverflow.com/questions/38436673/recognizing-mssql-service-broker-sender-side-error-messages