简体   繁体   English

我可以在python中实现SQL Server Service Broker吗?

[英]Can I implement SQL Server Service Broker in python?

是否可以实现服务代理以Python等语言从SQL Server接收消息,或者它是否总是必须使用某种.Net语言?

Yes it is possible (but not much fun) 是的,这是可能的(但不是很有趣)

Service Broker is configured and used via T-SQL commands, so if you have a way to talk to SQL Server from python (eg using the excellent pyodbc ) then you just have to connect and issue the appropriate queries. Service Broker是通过T-SQL命令配置和使用的,所以如果你有办法从python与SQL Server交谈(例如使用优秀的pyodbc ),那么你只需要连接并发出适当的查询。 Figuring out the appropriate T-SQL and getting Service Broker to work for you is the hard part, not the python bit. 弄清楚适当的T-SQL并让Service Broker为你工作是困难的部分,而不是python位。

import pyodbc

conn = pyodbc.connect(your_connection_string)
conn.autocommit = True
conn.execute("ALTER DATABASE CURRENT SET NEW_BROKER WITH ROLLBACK IMMEDIATE")

# ... etc ...

The rest of the (many hundreds of lines of) SQL is an exercise in understanding Service Broker, for which there is much MSDN documentation, such as the Developer's Guide for SQL Server 2008 R2. 其余的(数百行)SQL是理解Service Broker的练习,其中有许多MSDN文档,例如SQL Server 2008 R2 的开发人员指南

The community tutorials are very useful for figuring out stuff that Microsoft doesn't tell you eg these which I found helpful enough to get a proof-of-concept running before I gave it up :) 社区教程对于搞清楚微软没有告诉你的东西是非常有用的,例如我发现这些东西在我放弃它之前得到了足够有用的概念验证运行:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM