本文整理汇总了Python中azure.servicebus.ServiceBusService.send_topic_message方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceBusService.send_topic_message方法的具体用法?Python ServiceBusService.send_topic_message怎么用?Python ServiceBusService.send_topic_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.ServiceBusService
的用法示例。
在下文中一共展示了ServiceBusService.send_topic_message方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SweetieMQ
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_topic_message [as 别名]
class SweetieMQ(object):
bus_service = None
topic = None
def __init__(self, config):
account_key = getattr(config, 'sb_account_key', None)
issuer = getattr(config, 'sb_issuer', None)
if issuer is None:
issuer = 'owner'
if account_key is None:
return
self.bus_service = ServiceBusService(service_namespace='jabber-fimsquad',\
account_key=account_key, issuer=issuer)
self.topic = 'chat-general'
def send(self, message):
if self.bus_service is None:
return
log.debug('Sending message '+str(message))
msg = Message(message)
try:
self.bus_service.send_topic_message(self.topic, msg)
except Exception as e:
log.error("MESSAGE DELIVERY FAILED: "+str(e))
示例2: AzureBroker
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_topic_message [as 别名]
class AzureBroker(Thread):
def __init__(self):
Thread.__init__(self)
self._quit = Event()
self.daemon = True
self.log = logging.getLogger(__name__)
self.outgoing_topic = 'pending_jobs'
self.incoming_topic = 'finished_jobs'
self.notification_topic = 'jobs_changed'
self.subscription = 'AllMessages'
settings = Settings()
self.bus_service = ServiceBusService(
service_namespace=settings.azure_topic_namespace,
shared_access_key_name=settings.azure_topic_keyname,
shared_access_key_value=settings.azure_topic_key
)
self.bus_service.create_topic(self.incoming_topic)
self.bus_service.create_topic(self.outgoing_topic)
self.bus_service.create_topic(self.notification_topic)
self.bus_service.create_subscription(self.incoming_topic, self.subscription)
def run(self):
# dislike of unstoppable threads
while not self._quit.is_set():
msg = self.bus_service.receive_subscription_message(self.incoming_topic, self.subscription,
peek_lock=False, timeout=0.1)
if msg.body is not None:
self.log.info(msg.body + ":" + msg.custom_properties['job_id'])
notification_msg = Message('Finished'.encode('utf-8'), custom_properties={'job_id': msg.custom_properties['job_id']})
self.bus_service.send_topic_message(self.notification_topic, notification_msg)
sleep(3)
def transmit_job_created(self, job_id):
msg = Message('Created'.encode('utf-8'), custom_properties={'job_id': job_id})
self.bus_service.send_topic_message(self.outgoing_topic, msg)
self.bus_service.send_topic_message(self.notification_topic, msg)
self.log.info("Adding job " + job_id + " created to service bus.")
def transmit_job_assigned(self, job_id, machine_id):
msg = Message('Assigned'.encode('utf-8'), custom_properties={'job_id': job_id, 'machine_id': machine_id})
self.bus_service.send_topic_message(self.outgoing_topic, msg)
self.bus_service.send_topic_message(self.notification_topic, msg)
self.log.info("Adding job " + job_id + " assigned to " + machine_id + " to the service bus.")
def quit(self):
self._quit.set()
示例3: azure_autheticate
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_topic_message [as 别名]
def azure_autheticate():
key_name = 'beardcavekey' # SharedAccessKeyName from Azure portal
key_value = 'qc4xkJJlpEiRpcwCiD56dh/oxJBlhmM0gCwUcYw10GM=' # SharedAccessKey from Azure portal
service_namespace = 'beardcave'
sbs = ServiceBusService(service_namespace,
shared_access_key_name=key_name,
shared_access_key_value=key_value)
print "authenticated"
msg = Message('g3 off')
sbs.send_topic_message('lighttopic', msg)
# msg = sbs.receive_subscription_message('lighttopic', 'lightsubscription', peek_lock=True)
print(msg.body)
print "sent"
示例4: Notifier
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_topic_message [as 别名]
class Notifier():
def __init__(self, args):
if args.service_bus_namespace:
if args.verbose:
print 'Notifying via Azure Service Bus'
self.topic = args.service_bus_topic
self.service_bus = ServiceBusService(
service_namespace=args.service_bus_namespace,
account_key=args.service_bus_account_key,
issuer=args.service_bus_issuer)
else:
self.service_bus = None
def notify(self, detail, image):
title = 'You have an incoming call'
priority = 1 # high
if self.service_bus:
properties = {
'title': title,
'priority': priority,
'image': base64.b64encode(image)
}
msg = Message(detail, custom_properties=properties)
self.service_bus.send_topic_message(self.topic, msg)
示例5: ServiceBusTest
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_topic_message [as 别名]
#.........这里部分代码省略.........
deleted2 = self.sbs.delete_rule(
self.topic_name, 'MySubscription', '$Default', True)
# Assert
self.assertTrue(deleted1)
self.assertTrue(deleted2)
rules = self.sbs.list_rules(self.topic_name, 'MySubscription')
self.assertIsNotNone(rules)
self.assertEquals(len(rules), 1)
self.assertEquals(rules[0].name, 'MyRule3')
def test_delete_rule_with_non_existing_rule(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
# Act
deleted = self.sbs.delete_rule(
self.topic_name, 'MySubscription', 'NonExistingRule')
# Assert
self.assertFalse(deleted)
def test_delete_rule_with_non_existing_rule_fail_not_exist(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
# Act
with self.assertRaises(WindowsAzureError):
self.sbs.delete_rule(
self.topic_name, 'MySubscription', 'NonExistingRule', True)
# Assert
def test_send_topic_message(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
sent_msg = Message('subscription message')
# Act
self.sbs.send_topic_message(self.topic_name, sent_msg)
# Assert
def test_receive_subscription_message_read_delete_mode(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
sent_msg = Message('subscription message')
self.sbs.send_topic_message(self.topic_name, sent_msg)
# Act
received_msg = self.sbs.receive_subscription_message(
self.topic_name, 'MySubscription', False)
# Assert
self.assertIsNotNone(received_msg)
self.assertEquals(sent_msg.body, received_msg.body)
def test_receive_subscription_message_read_delete_mode_throws_on_delete(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
sent_msg = Message('subscription message')
self.sbs.send_topic_message(self.topic_name, sent_msg)
# Act
received_msg = self.sbs.receive_subscription_message(
self.topic_name, 'MySubscription', False)