async def test_send_custom_schema_event_as_list( self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint): akc_credential = AzureKeyCredential(eventgrid_topic_primary_key) client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential) custom_event1 = CustomEvent({ "customSubject": "sample", "customEventType": "sample.event", "customDataVersion": "2.0", "customId": "1234", "customEventTime": dt.datetime.now(UTC()).isoformat(), "customData": "sample data" }) custom_event2 = CustomEvent({ "customSubject": "sample2", "customEventType": "sample.event", "customDataVersion": "2.0", "customId": "12345", "customEventTime": dt.datetime.now(UTC()).isoformat(), "customData": "sample data 2" }) await client.send([custom_event1, custom_event2])
def publish_event(): # authenticate client credential = AzureKeyCredential(key) client = EventGridPublisherClient(topic_hostname, credential) custom_schema_event = { "customSubject": "sample", "customEventType": "sample.event", "customDataVersion": "2.0", "customId": uuid.uuid4(), "customEventTime": dt.datetime.now(UTC()).isoformat(), "customData": "sample data" } # publish events for _ in range(10): event_list = [] # list of events to publish # create events and append to list for j in range(randint(1, 3)): event = CustomEvent(custom_schema_event) event_list.append(event) # publish list of events client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5))
key = os.environ["CUSTOM_SCHEMA_ACCESS_KEY"] topic_hostname = os.environ["CUSTOM_SCHEMA_TOPIC_HOSTNAME"] # authenticate client credential = AzureKeyCredential(key) client = EventGridPublisherClient(topic_hostname, credential) custom_schema_event = { "customSubject": "sample", "customEventType": "sample.event", "customDataVersion": "2.0", "customId": uuid.uuid4(), "customEventTime": dt.datetime.now(UTC()).isoformat(), "customData": "sample data" } # publish events while True: event_list = [] # list of events to publish # create events and append to list for j in range(randint(1, 3)): event = CustomEvent(custom_schema_event) event_list.append(event) # publish list of events client.send(event_list) print("Batch of size {} published".format(len(event_list))) time.sleep(randint(1, 5))