Exemplo n.º 1
0
        internal static Message <T> Create(
            BasicGetResult result,
            IBusSerializer serializer,
            Action <Message <T> > onDone,
            Action <Exception, Message <T> > onFail)
        {
            var @event = new BasicDeliverEventArgs(
                string.Empty,
                result.DeliveryTag,
                result.Redelivered,
                result.Exchange,
                result.RoutingKey,
                result.BasicProperties,
                result.Body);

            return(Create(
                       null,
                       null,
                       null,
                       (RoutingKey)null,
                       serializer,
                       @event,
                       onDone,
                       onFail));
        }
Exemplo n.º 2
0
 public MessageOptions(Exchange exchange, Queue queue, RoutingKey routingKey, int maxAttempts, IBusSerializer serializer)
 {
     Exchange    = exchange;
     Queue       = queue;
     RoutingKey  = routingKey;
     MaxAttempts = maxAttempts;
     Serializer  = serializer;
 }
Exemplo n.º 3
0
 public CommandBus(string natsConnectionString, IBusLog log, IBusSerializer serializer)
 {
     log.Information($"Using natsconnection string: {natsConnectionString}");
     this.natsConnectionString = natsConnectionString;
     this.log           = log;
     this.serializer    = serializer;
     this.subscriptions = new List <IAsyncSubscription>();
 }
Exemplo n.º 4
0
 public BusConnection(BusConnectionString connectionString,
                      IBusSerializer serializer,
                      IServiceScopeFactory serviceScopeFactory,
                      IOptions <BusConnectionOptions> options,
                      IBusLogger logger            = null,
                      IRetryBehavior retryBehavior = null) : this(GetConnectionFactory(connectionString), serializer,
                                                                  serviceScopeFactory, options, logger, retryBehavior)
 {
 }
Exemplo n.º 5
0
 public Publisher(ILogger <Publisher <TSerializer, TDeserializer> > logger,
                  IServiceProvider provider, IEnumerable <IPublishSafeStore> safePoints)
 {
     _logger       = logger;
     _provider     = provider;
     _serializer   = provider.GetService <TSerializer>();
     _deserializer = provider.GetService <TDeserializer>();
     _stopper      = _deserializer == null ? Disposable.Empty : RunRepublishing(safePoints);
 }
Exemplo n.º 6
0
 public BusRpcServer(
     RabbitMQConnection connection,
     IBusSerializer busSerializer,
     IOptions <BusRpcOptions <TCommand, TResponse> > options,
     IMediator mediator)
 {
     _connection    = connection ?? throw new ArgumentNullException(nameof(connection));
     _busSerializer = busSerializer ?? throw new ArgumentNullException(nameof(busSerializer));
     _options       = options;
     _mediator      = mediator ?? throw new ArgumentNullException(nameof(mediator));
 }
Exemplo n.º 7
0
        public RabbitMQConnection(IConfiguration configuration, IBusSerializer busSerializer,
                                  IServiceProvider serviceProvider)
        {
            _busSerializer   = busSerializer ?? throw new ArgumentNullException(nameof(busSerializer));
            _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            var connectionFactory = new ConnectionFactory
            {
                Uri = new Uri(configuration.GetConnectionString("RabbitMQ"))
            };

            _connection = connectionFactory.CreateConnection();
            _channel    = _connection.CreateModel();
        }
Exemplo n.º 8
0
 public byte[] GetBody(IBusSerializer serializer)
 {
     if (serializer == null)
     {
         throw new ArgumentNullException(nameof(serializer));
     }
     if (_data is IConsumerMessage consumerMessage)
     {
         return(consumerMessage.Body);
     }
     return(_body.Length == 0
         ? _body = serializer.Serialize(_data)
         : _body);
 }
Exemplo n.º 9
0
 public ConsumerOptions(IBusSerializer serializer, Exchange exchange, Queue queue, ushort prefetchCount, Func <IServiceScope, Message <T>, Task> onNext, bool autoAck, int consumerMaxParallelTasks, params RoutingKey[] routingKeys)
 {
     if (prefetchCount <= 0)
     {
         throw new ArgumentException(nameof(prefetchCount));
     }
     Serializer               = serializer ?? throw new ArgumentNullException(nameof(serializer));
     Exchange                 = exchange ?? throw new ArgumentNullException(nameof(exchange));
     Queue                    = queue ?? throw new ArgumentNullException(nameof(queue));
     PrefetchCount            = prefetchCount;
     OnNext                   = onNext ?? throw new ArgumentNullException(nameof(onNext));
     AutoAck                  = autoAck;
     ConsumerMaxParallelTasks = consumerMaxParallelTasks;
     RoutingKeys              = routingKeys;
 }
Exemplo n.º 10
0
 public BusConnection(IConnectionFactory connectionFactory,
                      IBusSerializer serializer,
                      IServiceScopeFactory serviceScopeFactory,
                      IOptions <BusConnectionOptions> options,
                      IBusLogger logger            = null,
                      IRetryBehavior retryBehavior = null)
 {
     _serializer          = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _serviceScopeFactory = serviceScopeFactory;
     _logger            = logger;
     _options           = options;
     _consumers         = new ConcurrentBag <IConsumer>();
     _connectionFactory = connectionFactory;
     _publisherBuffer   =
         new BufferList <BatchItem>(_options.Value.PublisherBufferSize,
                                    TimeSpan.FromMilliseconds(_options.Value.PublisherBufferTtlInMilliseconds));
     _publisherBuffer.Cleared += PublishBufferOnCleared;
     _retryBehavior            = retryBehavior ?? new ConstantRetryBehavior(1);
 }
Exemplo n.º 11
0
 protected internal override (byte[], IBasicProperties) GetData(IModel channel, IBusSerializer serializer)
 {
     return(Data as byte[], _basicProperties);
 }
Exemplo n.º 12
0
        protected internal virtual (byte[], IBasicProperties) GetData(IModel channel, IBusSerializer serializer)
        {
            var body            = serializer.Serialize(Data).GetAwaiter().GetResult();
            var basicProperties = channel.CreateBasicProperties();

            basicProperties.Headers = new Dictionary <string, object>();
            basicProperties.Headers.Add(nameof(AttemptCount), AttemptCount);
            basicProperties.Headers.Add(nameof(MaxAttempts), MaxAttempts);
            return(body, basicProperties);
        }
Exemplo n.º 13
0
 public MessageBuilder(IModel channel, IBusSerializer serializer)
 {
     _channel    = channel;
     _serializer = serializer;
 }
Exemplo n.º 14
0
        protected internal virtual (byte[], IBasicProperties) GetData(IModel channel, IBusSerializer serializer)
        {
            var body            = serializer.Serialize(Data);
            var basicProperties = channel.CreateBasicProperties();

            basicProperties.Headers = new Dictionary <string, object>
            {
                { nameof(AttemptCount), AttemptCount },
                { nameof(MaxAttempts), MaxAttempts },
                { nameof(RequestKey), RequestKey }
            };
            return(body, basicProperties);
        }