def run():
        messaging_service = None
        try:
            reply_timeout = 10000
            topic_name = f'request_reply/pub_sub/sampler'
            topic = Topic.of(topic_name)
            topic_subscription = TopicSubscription.of(topic_name)
            messaging_service = MessagingService.builder().from_properties(SamplerBoot().broker_properties()).build()
            messaging_service.connect()

            HowToUseRequestReplyPattern.async_request_and_response(service=messaging_service,
                                                                   request_destination=topic,
                                                                   for_requests=topic_subscription,
                                                                   reply_timeout=reply_timeout)

            HowToUseRequestReplyPattern.blocking_request_and_response(service=messaging_service,
                                                                      request_destination=topic,
                                                                      for_requests=topic_subscription,
                                                                      reply_timeout=reply_timeout)
        finally:
            if messaging_service:
                messaging_service.disconnect()
コード例 #2
0
from typing import TypeVar

from solace.messaging.messaging_service import MessagingService
from solace.messaging.receiver.inbound_message import InboundMessage
from solace.messaging.receiver.persistent_message_receiver import PersistentMessageReceiver
from solace.messaging.resources.queue import Queue
from solace.messaging.resources.topic import Topic
from solace.messaging.resources.topic_subscription import TopicSubscription
from howtos.pubsub.how_to_consume_persistent_message import HowToConsumeMessageExclusiveVsSharedMode
from howtos.pubsub.how_to_publish_persistent_message import HowToPublishPersistentMessage
from howtos.sampler_boot import SolaceConstants, SamplerBoot, BasicTestMessageHandler
from howtos.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)


class HowToConsumePersistentMessageWithAutoAcknowledgement:
    """class contains methods to consume message with auto acknowledgement"""

    @staticmethod
    def consume_full_message_and_do_ack(service: MessagingService, queue_to_consume: Queue, publisher, message):
        receiver: PersistentMessageReceiver = service.create_persistent_message_receiver_builder() \
            .with_message_auto_acknowledgement().build(queue_to_consume)
        receiver.start()
        print(f'PERSISTENT receiver started... Listening to Queue [{queue_to_consume.get_name()}]')
"""sampler for configuring the transport layer security"""
import configparser
import os
from os.path import dirname
from solace.messaging.config.transport_security_strategy import TLS
from solace.messaging.errors.pubsubplus_client_error import PubSubPlusClientError
from solace.messaging.messaging_service import MessagingService
from howtos.sampler_boot import SamplerUtil, SamplerBoot

broker_properties_value = SamplerBoot.secured_broker_properties()


class HowToConnectWithTls:
    """sampler class for validating transport layer security configuration"""
    @staticmethod
    def tls_with_certificate_validation_and_trusted_store_settings(
            props, ignore_expiration: bool, trust_store_path: str):
        """method for validating tls certificate along with trusted store by providing the file path
        Args:
            props: broker properties
            trust_store_path (str): trust store file path
            ignore_expiration (bool): holds a boolean flag whether to ignore expiration or not

        Returns:
            a new connection to messaging service
        """
        try:
            transport_security = TLS.create() \
                .with_certificate_validation(ignore_expiration=ignore_expiration,
                                             trust_store_file_path=trust_store_path)
            messaging_service = MessagingService.builder().from_properties(props)\
コード例 #4
0
 def connect_messaging_service():
     messaging_service = MessagingService.builder().from_properties(
         SamplerBoot().broker_properties()).build()
     messaging_service.connect()
     return messaging_service
コード例 #5
0
        messaging_service.connect()
        return messaging_service

    @staticmethod
    def run_samplers():
        """method to run all the samplers"""
        HowToUseShareNameWithRequestReplyPattern.run()
        HowToUseRequestReplyPattern.run()
        HowToWorkWithSolaceSDTTypesAndMessages().run()
        HowToConnectMessagingService().run()
        HowToConfigureAuthentication.run()
        HowToConnectWithDifferentStrategy().run()
        HowToConnectWithTls.run()
        HowToDirectPublishMessage().run()
        HowToDirectMessagingHealthCheckSampler().run()
        HowToDirectPublishWithBackPressureSampler().run()
        HowToDirectConsumeBusinessObjectSampler().publish_and_subscribe()
        HowToAccessApiMetrics().run()
        HowToDirectConsumeSampler.run()
        HowToDirectConsumeShareNameSampler().publish_and_subscribe()
        #HowToSetCoreApiLogLevel.run()


if __name__ == '__main__':
    boot = SamplerBoot()
    broker_props = boot.broker_properties()
    semp_config = boot.read_semp_configuration()
    SamplerUtil.cert_feature(semp_props=semp_config, broker_props=broker_props)

    SamplerMaster.run_samplers()