示例#1
0
        public async Task RunAsync(CancellationToken token)
        {
            var writerTask = Task.Run(() => WriteMessages(_messageQueue, token), token);

            await using var reader_1 = await _messageQueue.GetReaderAsync(token);

            //await using var reader_2 = await _messageQueue.GetReaderAsync(token);

            var start_options_1 = new MessageQueueReaderStartOptions <MyMessage>(_handler)
            {
                //UserData = "1",
                SubscriptionName = "YOUR SUBSCRIPTION NAME HERE"
            };
            await reader_1.StartAsync(start_options_1, token);

            //var start_options_2 = new MessageReaderStartOptions<MyMessage>(_handler)
            //{
            //    UserData = "2",
            //    SubscriptionName = "YOUR SUBSCRIPTION NAME HERE"
            //};
            //await reader_2.StartAsync(start_options_2, token);

            await writerTask;

            Console.Write("press any key to exit");
            Console.ReadKey();

            await reader_1.StopAsync(token);

            //await reader_2.StopAsync(token);
        }
示例#2
0
        public ForwarderMessageQueue(ILogger <ForwarderMessageQueue <TMessage> > logger, IOptions <ForwarderMessageQueueOptions> options, IMessageQueue <TMessage> sourceQueue, IMessageQueue <TMessage> destinationQueue)
        {
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _options          = options?.Value ?? throw new ArgumentNullException(nameof(options));
            _sourceQueue      = sourceQueue ?? throw new ArgumentNullException(nameof(sourceQueue));
            _destinationQueue = destinationQueue ?? throw new ArgumentNullException(nameof(destinationQueue));

            var forwarderErrorHandler = _options.ForwardingErrorHandler ?? (_ => Task.FromResult(CompletionResult.Abandon));
            var startOptions          = new MessageQueueReaderStartOptions <TMessage>(new Handler <TMessage>(_logger, _destinationQueue, forwarderErrorHandler))
            {
                SubscriptionName = _options.SourceSubscriptionName,
                UserData         = _options.SourceUserData
            };

            // feels bad man
            _sourceReader = _sourceQueue.GetReaderAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();