def test_topic_backwards_compatibility_warning(self):
        # Arrange
        topic_options = Topic()
        topic_options.max_size_in_megabytes = 5120

        # Act
        val = topic_options.max_size_in_mega_bytes

        # Assert
        self.assertEqual(val, 5120)

        # Act
        topic_options.max_size_in_mega_bytes = 1024

        # Assert
        self.assertEqual(topic_options.max_size_in_megabytes, 1024)
예제 #2
0
    def test_topic_backwards_compatibility_warning(self):
        # Arrange
        topic_options = Topic()
        topic_options.max_size_in_megabytes = 5120

        # Act
        val = topic_options.max_size_in_mega_bytes

        # Assert
        self.assertEqual(val, 5120)

        # Act
        topic_options.max_size_in_mega_bytes = 1024

        # Assert
        self.assertEqual(topic_options.max_size_in_megabytes, 1024)
예제 #3
0
    def test_create_topic_with_options(self):
        # Arrange

        # Act
        topic_options = Topic()
        topic_options.default_message_time_to_live = 'PT1M'
        topic_options.duplicate_detection_history_time_window = 'PT5M'
        topic_options.enable_batched_operations = False
        topic_options.max_size_in_megabytes = 5120
        topic_options.requires_duplicate_detection = False
        topic_options.size_in_bytes = 0
        #TODO: MaximumNumberOfSubscriptions is not supported?
        created = self.sbs.create_topic(self.topic_name, topic_options)

        # Assert
        self.assertTrue(created)
        topic = self.sbs.get_topic(self.topic_name)
        self.assertEquals('PT1M', topic.default_message_time_to_live)
        self.assertEquals('PT5M',
                          topic.duplicate_detection_history_time_window)
        self.assertEquals(False, topic.enable_batched_operations)
        self.assertEquals(5120, topic.max_size_in_megabytes)
        self.assertEquals(False, topic.requires_duplicate_detection)
        self.assertEquals(0, topic.size_in_bytes)
    def test_create_topic_with_options(self):
        # Arrange

        # Act
        topic_options = Topic()
        topic_options.default_message_time_to_live = 'PT1M'
        topic_options.duplicate_detection_history_time_window = 'PT5M'
        topic_options.enable_batched_operations = False
        topic_options.max_size_in_megabytes = 5120 
        topic_options.requires_duplicate_detection = False
        topic_options.size_in_bytes = 0
        #TODO: MaximumNumberOfSubscriptions is not supported?
        created = self.sbs.create_topic(self.topic_name, topic_options)

        # Assert
        self.assertTrue(created)
        topic = self.sbs.get_topic(self.topic_name)
        self.assertEquals('PT1M', topic.default_message_time_to_live)
        self.assertEquals('PT5M', topic.duplicate_detection_history_time_window)
        self.assertEquals(False, topic.enable_batched_operations)
        self.assertEquals(5120, topic.max_size_in_megabytes)
        self.assertEquals(False, topic.requires_duplicate_detection)
        self.assertEquals(0, topic.size_in_bytes)
예제 #5
0
 def createTopic(self, topicName, topicOptions=None):
     if topicOptions is None:
         topicOptions = Topic()
         topicOptions.max_size_in_megabytes = '5120'
         topicOptions.default_message_time_to_live = 'PT1M'
     self.serviceBus.create_topic(topicName, topicOptions)
예제 #6
0
from azure.servicebus import ServiceBusService, Message, Topic, Rule, DEFAULT_RULE_NAME

namespaceName = 'yournamespace'  # Your service bus name, ex: 'whatever' (without single quotes. forget about .servicebus.windows.net )
accessName = 'RootManageSharedAccessKey'  # Your name, ex: 'owner' or 'RootManageSharedAccessKey'
accessKey = 'G6Iaa12aaB1aaHcZ4ghTzJKxLp1nFxf2hs1ZqYCSB5Y='  # Your key: ex: G6Iaa12aaB1aaHcZ4ghTzJKxLp1nFxf2hs1ZqYCSB5Y=

bus_service = ServiceBusService(service_namespace=namespaceName,
                                shared_access_key_name=accessName,
                                shared_access_key_value=accessKey)

topicName = 'test'
subscriptionName = 'readers'

topic_options = Topic()
topic_options.max_size_in_megabytes = '5120'
topic_options.default_message_time_to_live = 'PT1M'

bus_service.create_topic(topicName, topic_options)

bus_service.create_subscription(topicName, subscriptionName)

for i in range(5):
    msg = Message('Msg {0}'.format(i).encode('utf-8'),
                  custom_properties={'messagenumber': i})
    bus_service.send_topic_message(topicName, msg)

for i in range(5):
    msg = bus_service.receive_subscription_message(topicName,
                                                   subscriptionName,
                                                   peek_lock=False)
    print(msg.body)