def direct_message_publish_outbound_business_obj(
         messaging_service: MessagingService, destination, message_obj,
         converter):
     """ to publish outbound message from a custom object supplied with its own converter"""
     try:
         direct_publish_service = messaging_service.create_direct_message_publisher_builder(
         ).build()
         direct_publish_service.start_async()
         outbound_msg = messaging_service.message_builder() \
             .with_application_message_id(constants.APPLICATION_MESSAGE_ID) \
             .build(message_obj, converter=converter)
         direct_publish_service.publish(destination=destination,
                                        message=outbound_msg)
     finally:
         messaging_service.disconnect()
         direct_publish_service.terminate(0)
    def direct_message_consume_for_business_obj(
            messaging_service: MessagingService, consumer_subscription: str):
        """ to publish str or byte array type message"""
        try:
            global MAX_SLEEP
            topics = [TopicSubscription.of(consumer_subscription)]

            direct_receive_service = messaging_service.create_direct_message_receiver_builder(
            )
            direct_receive_service = direct_receive_service.with_subscriptions(
                topics).build()
            direct_receive_service.start()
            direct_receive_service.receive_async(MessageHandlerImpl())
            print(f"Subscribed to: {consumer_subscription}")
            time.sleep(MAX_SLEEP)
        finally:
            direct_receive_service.terminate()
            messaging_service.disconnect()
Exemple #3
0
 def direct_message_consume2(messaging_service: MessagingService,
                             consumer_subscription: str):
     """This method will create an receiver instance to receive str or byte array type message"""
     try:
         global MAX_SLEEP
         topics = [TopicSubscription.of(consumer_subscription)]
         group_name = ShareName.of('test')
         direct_receive_service = messaging_service.create_direct_message_receiver_builder(
         )
         direct_receive_service = direct_receive_service.with_subscriptions(
             topics).build(shared_subscription_group=group_name)
         direct_receive_service.start()
         direct_receive_service.receive_async(MessageHandlerImpl2())
         print(f"Subscribed to: {consumer_subscription}")
         time.sleep(MAX_SLEEP)
     finally:
         direct_receive_service.terminate()
         messaging_service.disconnect()
Exemple #4
0
def direct_message_consume(messaging_service: MessagingService,
                           topic_subscription: str):
    try:
        trace.set_tracer_provider(TracerProvider())
        jaeger_exporter = jaeger.JaegerSpanExporter(
            service_name="<Solace> REST Messaging call to Security Co",
            agent_host_name="localhost",
            agent_port=6831,
        )

        trace.get_tracer_provider().add_span_processor(
            BatchExportSpanProcessor(jaeger_exporter))

        tracer = trace.get_tracer(__name__)

        topics = [TopicSubscription.of(topic_subscription)]

        # Create a direct message consumer service with the topic subscription and start it
        direct_receive_service = messaging_service.create_direct_message_receiver_builder(
        )
        direct_receive_service = direct_receive_service.with_subscriptions(
            topics).build()
        direct_receive_service.start()

        # Register a callback message handler
        direct_receive_service.receive_async(MessageHandlerImpl())
        print(f"Subscribed to: {topic_subscription}")
        # Infinite loop until Keyboard interrupt is received
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            print('\nDisconnecting Messaging Service')
    finally:
        messaging_service.disconnect()
        direct_receive_service.terminate()