def direct_message_publish_outbound_with_all_props_on_backpressure_wait( messaging_service: MessagingService, destination, message, buffer_capacity, message_count): """ to publish outbound message using back pressure""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder() \ .on_back_pressure_wait(buffer_capacity=buffer_capacity) \ .build() direct_publish_service.start() outbound_msg = messaging_service.message_builder() \ .with_property("custom_key", "custom_value") \ .with_expiration(SolaceConstants.MESSAGE_EXPIRATION) \ .with_priority(SolaceConstants.MESSAGE_PRIORITY) \ .with_sequence_number(SolaceConstants.MESSAGE_SEQUENCE_NUMBER) \ .with_application_message_id(constants.APPLICATION_MESSAGE_ID) \ .with_application_message_type("app_msg_type") \ .with_http_content_header("text/html", "utf-8") \ .build(message) for e in range(message_count): direct_publish_service.publish(destination=destination, message=outbound_msg) except PublisherOverflowError: PublisherOverflowError("Queue maximum limit is reached") finally: util.publisher_terminate(direct_publish_service)
def direct_message_publish(messaging_service: MessagingService, topic, message): try: # Create a direct message publish service and start it direct_publish_service = messaging_service.create_direct_message_publisher_builder().build() direct_publish_service.start_async() # Publish the message! direct_publish_service.publish(destination=topic, message=message) finally: direct_publish_service.terminate()
def direct_message_publish(messaging_service: MessagingService, destination, message): """ to publish str or byte array type message""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder( ).build() direct_publish_service.start_async() direct_publish_service.publish(destination=destination, message=message) finally: direct_publish_service.terminate(0)
def direct_message_publish(messaging_service: MessagingService, destination, message): """ to publish str or byte array type message""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder(). \ on_back_pressure_reject(buffer_capacity=0).build() pub_start = direct_publish_service.start_async() pub_start.result() direct_publish_service.publish(destination=destination, message=message) finally: direct_publish_service.terminate()
def direct_message_publish_outbound_properties( messaging_service: MessagingService, destination, message): """ to publish outbound message with additional properties""" 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) \ .from_properties(constants.CUSTOM_PROPS).build(message) direct_publish_service.publish(destination=destination, message=outbound_msg) finally: direct_publish_service.terminate(0)
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().\ on_back_pressure_reject(buffer_capacity=0).build() publish_start = direct_publish_service.start_async() publish_start.result() 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: direct_publish_service.terminate()
def direct_message_publish_on_backpressure_reject( messaging_service: MessagingService, destination, message, buffer_capacity, message_count): """ to publish str or byte array type message using back pressure""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder() \ .on_back_pressure_reject(buffer_capacity=buffer_capacity) \ .build() direct_publish_service.start() for e in range(message_count): direct_publish_service.publish(destination=destination, message=message) except PublisherOverflowError: PublisherOverflowError("Queue maximum limit is reached") finally: util.publisher_terminate(direct_publish_service)
def direct_message_publish_outbound_with_all_props( messaging_service: MessagingService, destination, message): """ to publish outbound message""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder( ).build() direct_publish_service.start_async() outbound_msg = messaging_service.message_builder() \ .with_property("custom_key", "custom_value") \ .with_expiration(SolaceConstants.DEFAULT_TIMEOUT_MS) \ .with_priority(1) \ .with_sequence_number(12345) \ .with_application_message_id(constants.APPLICATION_MESSAGE_ID) \ .with_application_message_type("app_msg_type") \ .with_http_content_header("text/html", _sol_constants.ENCODING_TYPE) \ .build(message) direct_publish_service.publish(destination=destination, message=outbound_msg) finally: direct_publish_service.terminate(0)
def publish_SDTMap(messaging_service: MessagingService, destination, message): """ to publish message""" # Create a direct message publisher and start it try: direct_publisher = messaging_service.create_direct_message_publisher_builder( ).build() direct_publisher.set_publish_failure_listener( PublisherErrorHandling()) # direct_publisher.set_publisher_readiness_listener() # Blocking Start thread direct_publisher.start() print(f'Direct Publisher ready? {direct_publisher.is_ready()}') print("Publishing message... : ", message) direct_publisher.publish(destination=destination, message=message) print("Message published!") finally: direct_publisher.terminate(500000) print("Publisher disconnected!")
def notify_on_direct_publisher_failures(messaging_service: MessagingService, destination_name, message, buffer_capacity, message_count): """ configure direct message publisher to receive notifications about publish failures if any occurred """ try: direct_publish_service = messaging_service.create_direct_message_publisher_builder() \ .on_back_pressure_reject(buffer_capacity=buffer_capacity) \ .build() direct_publish_service.start() publish_failure_listener = PublishFailureListenerImpl() direct_publish_service.set_publish_failure_listener(publish_failure_listener) outbound_msg = messaging_service.message_builder() \ .with_application_message_id(constants.APPLICATION_MESSAGE_ID) \ .build(message) direct_publish_service.publish(destination=destination_name, message=outbound_msg) finally: direct_publish_service.terminate_async()
def direct_message_publish_without_backpressure( messaging_service: MessagingService, destination, message, message_count): """ to publish str or byte array type message using back pressure""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder() \ .build() direct_publish_service.start_async() HowToDirectMessagingHealthCheckSampler.PUBLISHER_READINESS_SET_COUNTER += 1 direct_publish_service.set_publisher_readiness_listener( listener=PublisherReadinessListenerImpl()) for e in range(message_count): direct_publish_service.publish(destination=destination, message=message) print(f"{e} message(s) sent") except PublisherOverflowError: PublisherOverflowError("Queue maximum limit is reached") finally: direct_publish_service.terminate()
def direct_message_publish_outbound_with_all_props_on_backpressure_elastic( messaging_service: MessagingService, destination, message, message_count): """ to publish outbound message using back pressure""" try: direct_publish_service = messaging_service.create_direct_message_publisher_builder() \ .on_back_pressure_elastic() \ .build() direct_publish_service.start() outbound_msg = messaging_service.message_builder() \ .with_property("custom_key", "custom_value") \ .with_expiration(SolaceConstants.MESSAGE_EXPIRATION) \ .with_priority(SolaceConstants.MESSAGE_PRIORITY) \ .with_sequence_number(SolaceConstants.MESSAGE_SEQUENCE_NUMBER) \ .with_application_message_id(constants.APPLICATION_MESSAGE_ID) \ .with_application_message_type("app_msg_type") \ .with_http_content_header("text/html", "utf-8") \ .build(message) for e in range(message_count): direct_publish_service.publish(destination=destination, message=outbound_msg) finally: direct_publish_service.terminate()