from solace.messaging.config.solace_properties import service_properties from solace.messaging.config.solace_properties.message_properties import CORRELATION_ID, PRIORITY from solace.messaging.receiver.inbound_message import InboundMessage from solace.messaging.resources.queue import Queue from solace.messaging.resources.topic import Topic from solace.messaging.resources.topic_subscription import TopicSubscription from solace_sampler.SEMPv2.semp_client import SempClient from solace_sampler.SEMPv2.semp_utility import SempUtility from solace_sampler.pubsub.how_to_publish_persistent_message import HowToPublishPersistentMessage from solace_sampler.sampler_boot import SolaceConstants, SamplerBoot, BasicTestMessageHandler, \ ReceiverStateChangeListenerImpl from solace_sampler.sampler_master import SamplerMaster X = TypeVar('X') constants = SolaceConstants boot = SamplerBoot() lock = threading.Lock() topic_name = constants.TOPIC_ENDPOINT_DEFAULT topic = Topic.of(topic_name) boot = SamplerBoot() broker_props = boot.broker_properties() semp_config = boot.read_semp_configuration() semp_obj = SempClient(semp_base_url=semp_config[SamplerBoot.semp_hostname_key], user_name=semp_config[SamplerBoot.semp_username_key], password=semp_config[SamplerBoot.semp_password_key]) semp = SempUtility(semp_obj)
import pickle import time from concurrent.futures.thread import ThreadPoolExecutor from typing import TypeVar, Generic from solace.messaging.messaging_service import MessagingService from solace.messaging.receiver.message_receiver import MessageHandler from solace.messaging.resources.topic_subscription import TopicSubscription from solace.messaging.utils.converter import BytesToObject from solace_sampler.pubsub.how_to_direct_publish_message import HowToDirectPublishMessage from solace_sampler.sampler_boot import SamplerBoot, SolaceConstants X = TypeVar('X') constants = SolaceConstants boot = SamplerBoot() MAX_SLEEP = 10 class MessageHandlerImpl1(MessageHandler): """this method is an call back handler to receive message""" def on_message(self, message: 'InboundMessage'): """ Message receive callback """ topic = message.get_destination_name() payload_as_bytes = message.get_payload_as_bytes() payload_as_string = message.get_payload_as_string() correlation_id = message.get_correlation_id() print("\n" + f"CALLBACK: Message Received on Topic: {topic}.\n" f"Message Bytes: {payload_as_bytes} \n" f"Message String: {payload_as_string} \n" f"Correlation id: {correlation_id}")
def connect_messaging_service(): messaging_service = MessagingService.builder().from_properties( SamplerBoot().broker_properties()).build() messaging_service.connect() return messaging_service