Beispiel #1
0
        public SentMessageExtensionsTests()
        {
            var timeout = TimeSpan.FromSeconds(3);

            CancellationTokenSource = new CancellationTokenSource(timeout);

            var messageSerializationService = new MessageMarshaller();
            var diagnosticService           = DiagnosticService.DefaultInstance;

            ReplyHub = new MemoryCacheReplyHub(
                messageSerializationService,
                diagnosticService,
                timeout);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new <see cref="Bus"/> with the specified configuration and services
        /// provided by the host
        /// </summary>
        /// <param name="configuration">The core bus configuration</param>
        /// <param name="baseUri">The base URI provided by the host</param>
        /// <param name="transportService">The transport service provided by the host</param>
        /// <param name="messageQueueingService">The message queueing service provided by the host</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception>
        public Bus(IPlatibusConfiguration configuration, Uri baseUri, ITransportService transportService, IMessageQueueingService messageQueueingService)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            // Validate the provided configuration and throw exceptions for missing or invalid
            // configurations
            configuration.Validate();

            _baseUri                = baseUri ?? throw new ArgumentNullException(nameof(baseUri));
            _transportService       = transportService ?? throw new ArgumentNullException(nameof(transportService));
            _messageQueueingService = messageQueueingService ?? throw new ArgumentNullException(nameof(messageQueueingService));
            _defaultContentType     = string.IsNullOrWhiteSpace(configuration.DefaultContentType)
                ? "application/json"
                : configuration.DefaultContentType;

            _defaultSendOptions = configuration.DefaultSendOptions ?? new SendOptions();

            _messageMarshaller = new MessageMarshaller(
                configuration.MessageNamingService,
                configuration.SerializationService,
                configuration.DefaultContentType);

            _endpoints     = configuration.Endpoints ?? EndpointCollection.Empty;
            _topics        = configuration.Topics.ToList();
            _sendRules     = configuration.SendRules.ToList();
            _handlingRules = configuration.HandlingRules.ToList();
            _subscriptions = configuration.Subscriptions.ToList();

            _diagnosticService = configuration.DiagnosticService;
            _messageHandler    = new MessageHandler(_messageMarshaller, _diagnosticService);

            _transportService.MessageReceived += OnMessageReceived;

            _replyHub = new MemoryCacheReplyHub(_messageMarshaller, _diagnosticService, TimeSpan.FromMinutes(5));
        }
Beispiel #3
0
 /// <summary>
 /// Creates a new <see cref="MemoryCacheReplyHub"/> that will hold sent messages
 /// in memory until the specified <paramref name="replyTimeout"/> has elapsed
 /// </summary>
 /// <param name="messageMarshaller">A service used to deserialize message content</param>
 /// <param name="diagnosticService">A service through which diagnostic events related
 /// to handling replies will be reported</param>
 /// <param name="replyTimeout">The maximum amount of time to hold send messages
 ///     in memory before they are evicted from cache</param>
 public MemoryCacheReplyHub(MessageMarshaller messageMarshaller, IDiagnosticService diagnosticService, TimeSpan replyTimeout)
 {
     _messageMarshaller = messageMarshaller ?? throw new ArgumentNullException(nameof(messageMarshaller));
     _diagnosticService = diagnosticService ?? throw new ArgumentNullException(nameof(diagnosticService));
     _replyTimeout      = replyTimeout <= TimeSpan.Zero ? TimeSpan.FromMinutes(5) : replyTimeout;
 }
Beispiel #4
0
 public MessageHandler(MessageMarshaller messageMarshaller, IDiagnosticService diagnosticService = null)
 {
     _diagnosticService = diagnosticService ?? DiagnosticService.DefaultInstance;
     _messageMarshaller = messageMarshaller ?? throw new ArgumentNullException(nameof(messageMarshaller));
 }