コード例 #1
0
ファイル: server.py プロジェクト: pCresp0/ztreamy
def publish_there():
    print('Publishing "there"')
    app_id = random.choice(application_ids)
    event = ztreamy.Event(source_id,
                          'text/plain',
                          'there!',
                          application_id=app_id)
    publisher2.publish(event)
コード例 #2
0
 def test_unicode_fields(self):
     event = ztreamy.Event(u'7272727828',
                           u'text/plain',
                           u'ásddf'.encode('utf-8'),
                           event_id=u'777888333',
                           application_id=u'app',
                           aggregator_id=[u'234234234', '3333', u'324234'],
                           event_type=u'TestType',
                           timestamp=u'20150714T16:29:00+0200',
                           extra_headers={u'X-Header': u'value'})
     serialized = str(event)
     deserializer = ztreamy.Deserializer()
     deserialized = deserializer.deserialize(serialized, complete=True)
     self.assertEqual(len(deserialized), 1)
     self.assertEqual(event.source_id, deserialized[0].source_id)
     self.assertEqual(event.syntax, deserialized[0].syntax)
     self.assertEqual(event.body, deserialized[0].body)
     self.assertEqual(event.event_id, deserialized[0].event_id)
     self.assertEqual(event.aggregator_id, deserialized[0].aggregator_id)
     self.assertEqual(event.event_type, deserialized[0].event_type)
     self.assertEqual(event.timestamp, deserialized[0].timestamp)
     self.assertEqual(event.extra_headers, deserialized[0].extra_headers)
コード例 #3
0
    def PublishData(self, stream_path, stream_name, stream_content, frequency):

        # input_ztreamy_url + input_ztreamy_stream + "/publish"

        print "stream path: " + stream_path
        result = True

        try:

            # send data to server:
            publisher = ZtreamyClient(stream_path)

            for stream_event in stream_content:

                source_id = stream_name

                try:

                    event = ztreamy.Event(source_id, 'text/plain',
                                          stream_event)
                    result = publisher.publish(event)
                    publisher.close()
                    logging.info("Success publishing data to ztreamy")

                except KeyboardInterrupt:
                    # Allow ctrl-c to finish the program
                    logging.exception("Sending data to ztreamy interrupted")
                    return False

                finally:
                    publisher.close()

        except:
            logging.exception("Failed to publish data to ztreamy")
            return False

        return result
コード例 #4
0
ファイル: server.py プロジェクト: pCresp0/ztreamy
def publish_hi():
    print('Publishing "hi"')
    app_id = random.choice(application_ids)
    event = ztreamy.Event(source_id, 'text/plain', 'Hi', application_id=app_id)
    publisher1.publish(event)
コード例 #5
0
ファイル: publisher_async.py プロジェクト: pCresp0/ztreamy
def publish():
    print('Publishing')
    event = ztreamy.Event(source_id, 'text/plain',  'This is a new event')
    publisher.publish(event)
コード例 #6
0
ファイル: publisher_sync.py プロジェクト: pCresp0/ztreamy
import time

import ztreamy

# Create a publisher object
stream = 'http://localhost:9000/stream1'
publisher = ztreamy.SynchronousEventPublisher(stream)
source_id = ztreamy.random_id()

try:
    while True:
        time.sleep(10)
        event = ztreamy.Event(source_id, 'text/plain',  'This is a new event')
        publisher.publish(event)
except KeyboardInterrupt:
    # Allow ctrl-c to finish the program
    pass
finally:
    publisher.close()