private LinkConsumerBuilder(
     LinkConsumerBuilder prev,
     TimeSpan?recoveryInterval = null,
     ushort?prefetchCount      = null,
     bool?autoAck            = null,
     int?priority            = null,
     bool?cancelOnHaFailover = null,
     bool?exclusive          = null,
     ILinkConsumerErrorStrategy errorStrategy = null,
     LinkConsumerMessageHandlerBuilder messageHandlerBuilder = null,
     ILinkConsumerTopologyHandler topologyHandler            = null,
     LinkStateHandler <LinkConsumerState> stateHandler       = null,
     LinkStateHandler <LinkChannelState> channelStateHandler = null,
     ILinkSerializer serializer          = null,
     LinkTypeNameMapping typeNameMapping = null
     ) : this
     (
         prev._link,
         recoveryInterval ?? prev._reconveryInterval,
         serializer ?? prev._serializer,
         prefetchCount ?? prev._prefetchCount,
         autoAck ?? prev._autoAck,
         priority ?? prev._priority,
         cancelOnHaFailover ?? prev._cancelOnHaFailover,
         exclusive ?? prev._exclusive,
         errorStrategy ?? prev._errorStrategy,
         messageHandlerBuilder ?? prev._messageHandlerBuilder,
         topologyHandler ?? prev._topologyHandler,
         stateHandler ?? prev._stateHandler,
         channelStateHandler ?? prev._channelStateHandler,
         typeNameMapping ?? prev._typeNameMapping
     )
 {
 }
Esempio n. 2
0
        public LinkPullConsumer(
            ILinkConsumerBuilder consumerBuilder,
            TimeSpan getMessageTimeout,
            LinkTypeNameMapping typeNameMapping,
            ILinkSerializer serializer
            )
        {
            if (consumerBuilder == null)
            {
                throw new ArgumentNullException(nameof(consumerBuilder));
            }

            if (getMessageTimeout < TimeSpan.Zero && getMessageTimeout != Timeout.InfiniteTimeSpan)
            {
                throw new ArgumentOutOfRangeException(nameof(getMessageTimeout),
                                                      "Must be greater or equal zero or equal Timeout.InfiniteTimeSpan");
            }

            GetMessageTimeout = getMessageTimeout;
            _typeNameMapping  = typeNameMapping ?? throw new ArgumentNullException(nameof(typeNameMapping));
            _serializer       = serializer;

            _consumer = consumerBuilder
                        .ErrorStrategy(new LinkConsumerDefaultErrorStrategy())
                        .Handler(OnMessageReceived)
                        .OnStateChange(OnStateChanged)
                        .Build();
        }
        public LinkConsumerConfiguration(
            TimeSpan recoveryInterval,
            ushort prefetchCount,
            bool autoAck,
            int priority,
            bool cancelOnHaFailover,
            bool exclusive,
            ILinkConsumerTopologyHandler topologyHandler,
            LinkStateHandler<LinkConsumerState> stateHandler,
            ILinkConsumerErrorStrategy errorStrategy,
            LinkConsumerMessageHandlerDelegate<byte[]> messageHandler,
            ILinkSerializer serializer
        )
        {
            if (recoveryInterval < TimeSpan.Zero)
                throw new ArgumentOutOfRangeException(nameof(recoveryInterval), "Must be greater than TimeSpan.Zero");
            
            if(prefetchCount == 0)
                throw new ArgumentOutOfRangeException(nameof(prefetchCount), "Must be greater than 0");

            RecoveryInterval = recoveryInterval;
            PrefetchCount = prefetchCount;
            AutoAck = autoAck;
            Priority = priority;
            CancelOnHaFailover = cancelOnHaFailover;
            Exclusive = exclusive;
            MessageHandler = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));
            ErrorStrategy = errorStrategy ?? throw new ArgumentNullException(nameof(errorStrategy));
            TopologyHandler = topologyHandler ?? throw new ArgumentNullException(nameof(topologyHandler));
            StateHandler = stateHandler ?? throw new ArgumentNullException(nameof(stateHandler));
            Serializer = serializer;
        }
        public LinkConsumerBuilder(
            Link link,
            TimeSpan recoveryInterval,
            ILinkSerializer serializer,
            ushort?prefetchCount    = null,
            bool?autoAck            = null,
            int?priority            = null,
            bool?cancelOnHaFailover = null,
            bool?exclusive          = null,
            ILinkConsumerErrorStrategy errorStrategy = null,
            LinkConsumerMessageHandlerBuilder messageHandlerBuilder = null,
            ILinkConsumerTopologyHandler topologyHandler            = null,
            LinkStateHandler <LinkConsumerState> stateHandler       = null,
            LinkStateHandler <LinkChannelState> channelStateHandler = null,
            LinkTypeNameMapping typeNameMapping = null
            )
        {
            _link = link ?? throw new ArgumentNullException(nameof(link));

            _reconveryInterval     = recoveryInterval;
            _prefetchCount         = prefetchCount ?? 1;
            _autoAck               = autoAck ?? false;
            _priority              = priority ?? 0;
            _cancelOnHaFailover    = cancelOnHaFailover ?? false;
            _exclusive             = exclusive ?? false;
            _errorStrategy         = errorStrategy ?? new LinkConsumerDefaultErrorStrategy();
            _messageHandlerBuilder = messageHandlerBuilder;
            _topologyHandler       = topologyHandler;
            _stateHandler          = stateHandler ?? ((old, @new) => { });
            _channelStateHandler   = channelStateHandler ?? ((old, @new) => { });
            _serializer            = serializer;
            _typeNameMapping       = typeNameMapping ?? new LinkTypeNameMapping();
        }
        /// <summary>
        ///     Deserialize messsage and set properties
        /// </summary>
        public static object Deserialize(this ILinkSerializer @this, Type bodyType,
                                         byte[] body, LinkMessageProperties properties)
        {
            var genericMethod = DeserializeMethod.MakeGenericMethod(bodyType);

            return(genericMethod.Invoke(@this, new object[] { body, properties }));
        }
Esempio n. 6
0
 private LinkProducerBuilder
 (
     LinkProducerBuilder prev,
     TimeSpan?recoveryInterval = null,
     TimeSpan?publishTimeout   = null,
     bool?confirmsMode         = null,
     bool?setUserId            = null,
     ILinkMessageIdGenerator messageIdGenerator              = null,
     LinkPublishProperties publishProperties                 = null,
     LinkMessageProperties messageProperties                 = null,
     ILinkProducerTopologyHandler topologyHandler            = null,
     LinkStateHandler <LinkProducerState> stateHandler       = null,
     LinkStateHandler <LinkChannelState> channelStateHandler = null,
     ILinkSerializer serializer          = null,
     LinkTypeNameMapping typeNameMapping = null
 ) : this
     (
         prev._link,
         recoveryInterval ?? prev._recoveryInterval,
         serializer ?? prev._serializer,
         publishTimeout ?? prev._publishTimeout,
         confirmsMode ?? prev._confirmsMode,
         setUserId ?? prev._setUserId,
         messageIdGenerator ?? prev._messageIdGenerator,
         publishProperties ?? prev._publishProperties.Clone(),
         messageProperties ?? prev._messageProperties.Clone(),
         topologyHandler ?? prev._topologyHandler,
         stateHandler ?? prev._stateHandler,
         channelStateHandler ?? prev._channelStateHandler,
         typeNameMapping ?? prev._typeNameMapping
     )
 {
 }
Esempio n. 7
0
        public LinkProducerBuilder
        (
            Link link,
            TimeSpan recoveryInterval,
            ILinkSerializer serializer,
            TimeSpan?publishTimeout = null,
            bool?confirmsMode       = null,
            bool?setUserId          = null,
            ILinkMessageIdGenerator messageIdGenerator              = null,
            LinkPublishProperties publishProperties                 = null,
            LinkMessageProperties messageProperties                 = null,
            ILinkProducerTopologyHandler topologyHandler            = null,
            LinkStateHandler <LinkProducerState> stateHandler       = null,
            LinkStateHandler <LinkChannelState> channelStateHandler = null,
            LinkTypeNameMapping typeNameMapping = null
        )
        {
            _link = link ?? throw new ArgumentNullException(nameof(link));

            _confirmsMode        = confirmsMode ?? false;
            _setUserId           = setUserId ?? true;
            _publishTimeout      = publishTimeout ?? Timeout.InfiniteTimeSpan;
            _recoveryInterval    = recoveryInterval;
            _messageIdGenerator  = messageIdGenerator ?? new LinkGuidMessageIdGenerator();
            _publishProperties   = publishProperties ?? new LinkPublishProperties();
            _messageProperties   = messageProperties ?? new LinkMessageProperties();
            _topologyHandler     = topologyHandler;
            _stateHandler        = stateHandler ?? ((old, @new) => { });
            _channelStateHandler = channelStateHandler ?? ((old, @new) => { });
            _serializer          = serializer;
            _typeNameMapping     = typeNameMapping ?? new LinkTypeNameMapping();
        }
Esempio n. 8
0
 private LinkBuilder(
     LinkBuilder prev,
     string connectionName            = null,
     Uri connectionString             = null,
     bool?autoStart                   = null,
     TimeSpan?timeout                 = null,
     TimeSpan?recoveryInterval        = null,
     ILinkLoggerFactory loggerFactory = null,
     string appId = null,
     LinkStateHandler <LinkConnectionState> stateHandler = null,
     bool?useBackgroundThreadsForConnection = null,
     ILinkSerializer serializer             = null
     ) : this(
         connectionName ?? prev._connectionName,
         connectionString ?? prev._connectionString,
         autoStart ?? prev._autoStart,
         timeout ?? prev._timeout,
         recoveryInterval ?? prev._recoveryInterval,
         loggerFactory ?? prev._loggerFactory,
         appId ?? prev._appId,
         stateHandler ?? prev._stateHandler,
         useBackgroundThreadsForConnection ?? prev._useBackgroundThreadsForConnection,
         serializer ?? prev._serializer
         )
 {
 }
        public ILinkConsumerBuilder Serializer(ILinkSerializer value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(new LinkConsumerBuilder(this, serializer: value));
        }
 public LinkPullConsumerBuilder(
     ILinkConsumerBuilder consumerBuilder,
     LinkTypeNameMapping typeNameMapping,
     ILinkSerializer serializer,
     TimeSpan?getMessageTimeout = null
     )
 {
     _serializer        = serializer;
     _consumerBuilder   = consumerBuilder ?? throw new ArgumentNullException(nameof(consumerBuilder));
     _getMessageTimeout = getMessageTimeout ?? Timeout.InfiniteTimeSpan;
     _typeNameMapping   = typeNameMapping ?? throw new ArgumentNullException(nameof(typeNameMapping));
     _serializer        = serializer;
 }
 private LinkPullConsumerBuilder(
     LinkPullConsumerBuilder prev,
     ILinkConsumerBuilder consumerBuilder = null,
     LinkTypeNameMapping typeNameMapping  = null,
     ILinkSerializer serializer           = null,
     TimeSpan?getMessageTimeout           = null
     ) : this(
         consumerBuilder ?? prev._consumerBuilder,
         typeNameMapping ?? prev._typeNameMapping,
         serializer ?? prev._serializer,
         getMessageTimeout ?? prev._getMessageTimeout
         )
 {
 }
Esempio n. 12
0
        public LinkConfiguration(
            string connectionName,
            Uri connectionString,
            bool autoStart,
            TimeSpan timeout,
            TimeSpan recoveryInterval,
            ILinkLoggerFactory loggerFactory,
            string appId,
            LinkStateHandler <LinkConnectionState> stateHandler,
            bool useBackgroundThreadsForConnection,
            ILinkSerializer serializer
            )
        {
            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ArgumentNullException(nameof(connectionName));
            }

            if (timeout <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(timeout), "Must be greater than TimeSpan.Zero");
            }

            if (recoveryInterval <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(recoveryInterval), "Must be greater than TimeSpan.Zero");
            }

            if (string.IsNullOrWhiteSpace(appId))
            {
                throw new ArgumentNullException(nameof(appId));
            }

            ConnectionName   = connectionName.Trim();
            ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            AutoStart        = autoStart;
            Timeout          = timeout;
            RecoveryInterval = recoveryInterval;
            LoggerFactory    = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            AppId            = appId.Trim();
            StateHandler     = stateHandler ?? throw new ArgumentNullException(nameof(stateHandler));
            UseBackgroundThreadsForConnection = useBackgroundThreadsForConnection;
            Serializer = serializer;
        }
        public LinkProducerConfiguration(
            TimeSpan publishTimeout,
            TimeSpan recoveryInterval,
            ILinkMessageIdGenerator messageIdGenerator,
            bool confirmsMode,
            bool setUserId,
            LinkPublishProperties publishProperties,
            LinkMessageProperties messageProperties,
            ILinkProducerTopologyHandler topologyHandler,
            LinkStateHandler <LinkProducerState> stateHandler,
            ILinkSerializer serializer,
            LinkTypeNameMapping typeNameMapping
            )
        {
            if (publishTimeout < TimeSpan.Zero && publishTimeout != Timeout.InfiniteTimeSpan)
            {
                throw new ArgumentOutOfRangeException(nameof(publishTimeout),
                                                      "Must be greater or equal TimeSpan.Zero or equal Timeout.InfiniteTimeSpan");
            }

            if (recoveryInterval < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(recoveryInterval), "Must be greater than TimeSpan.Zero");
            }

            PublishTimeout     = publishTimeout;
            RecoveryInterval   = recoveryInterval;
            MessageIdGenerator = messageIdGenerator ?? throw new ArgumentNullException(nameof(messageIdGenerator));
            ConfirmsMode       = confirmsMode;
            SetUserId          = setUserId;
            _publishProperties = publishProperties ?? throw new ArgumentNullException(nameof(publishProperties));
            _messageProperties = messageProperties ?? throw new ArgumentNullException(nameof(messageProperties));
            TopologyHandler    = topologyHandler ?? throw new ArgumentNullException(nameof(topologyHandler));
            StateHandler       = stateHandler ?? throw new ArgumentNullException(nameof(stateHandler));
            Serializer         = serializer;
            TypeNameMapping    = typeNameMapping ?? throw new ArgumentNullException(nameof(typeNameMapping));
        }
Esempio n. 14
0
 public LinkBuilder(
     string connectionName            = null,
     Uri connectionString             = null,
     bool?autoStart                   = null,
     TimeSpan?timeout                 = null,
     TimeSpan?recoveryInterval        = null,
     ILinkLoggerFactory loggerFactory = null,
     string appId = null,
     LinkStateHandler <LinkConnectionState> stateHandler = null,
     bool?useBackgroundThreadsForConnection = null,
     ILinkSerializer serializer             = null
     )
 {
     _connectionName   = connectionName ?? "default";
     _connectionString = connectionString;
     _autoStart        = autoStart ?? true;
     _timeout          = timeout ?? TimeSpan.FromSeconds(10);
     _recoveryInterval = recoveryInterval;
     _loggerFactory    = loggerFactory ?? new LinkNullLoggingFactory();
     _appId            = appId ?? Guid.NewGuid().ToString("D");
     _stateHandler     = stateHandler ?? ((old, @new) => { });
     _useBackgroundThreadsForConnection = useBackgroundThreadsForConnection ?? false;
     _serializer = serializer;
 }
Esempio n. 15
0
 public IServiceLinkBuilder Serializer(ILinkSerializer serializer)
 => new ServiceLinkBuilder(_linkBuilder.Serializer(serializer), Store);