Why do I need two SQL Server Service Broker queues for a simple task?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 10:47:58

Technically you can use one queue using SSB technology in your application. In this case this queue has a mess from request messages from initiator and response messages from target. Your stored procedure should implement mechanism to distinguish one from another, sort out them, decide which response is for which request and so on. Also take in mind that RECEIVE messages from this queue in exact order and you can't skip some of them and leave in queue for further processing.

Maybe better in your case to follow Remus Rusanu's answer and implement your queue using database table?

SSB idea is simple - Initiator places request message into Target's queue while waiting response message from Target in its own queue. Is it your case? If no, maybe you need not SSB at all?

Service Broker has basically nothing to do with queues. Service Broker is for writing distributed applications, not for queuing. Queues are simply message stores for service, and one service is on one machine while the other service is on a second machine. Examples may show both services in the same database just for simplicity sake, but the example is still about communicating in a distributed environment.

Examples that show case where a single queue apparently is enough are using Service Broker incorrectly. Those examples should better show how to use tables as queues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!