public ICanCreateEndpointAsClientOrServer <TMessage, TCommand, TEvent, TRequest, TResponse> SerializedWith(IMessageSerializer serializer,
                                                                                                            IMessageDeserializerFactory deserializerFactory)
 {
     _serializer          = serializer;
     _deserializerFactory = deserializerFactory;
     return(this);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="serviceName">Service name</param>
 /// <param name="queueNamesByMessageType">Queue names by message type</param>
 /// <param name="cloudQueueClient">Cloud queue client</param>
 /// <param name="serializer">Serializer</param>
 /// <param name="deserializerFactory">Deserializer factory</param>
 /// <param name="queueRequestOptionsByMessageType">Queue request options</param>
 /// <param name="maxMessagesToDequeue">Queue request options</param>
 public AzureStorageQueueServiceEndpointProvider(
     string serviceName,
     IDictionary <Type, string> queueNamesByMessageType,
     CloudQueueClient cloudQueueClient,
     IMessageSerializer serializer,
     IMessageDeserializerFactory deserializerFactory,
     IDictionary <Type, QueueRequestOptions> queueRequestOptionsByMessageType = null,
     int maxMessagesToDequeue = 1
     ) : base(serviceName)
 {
     if (string.IsNullOrEmpty(serviceName))
     {
         throw new ArgumentNullException(nameof(serviceName));
     }
     if (cloudQueueClient == null)
     {
         throw new ArgumentNullException(nameof(cloudQueueClient));
     }
     if (serializer == null)
     {
         throw new ArgumentNullException(nameof(serializer));
     }
     if (deserializerFactory == null)
     {
         throw new ArgumentNullException(nameof(deserializerFactory));
     }
     _serviceName             = serviceName;
     _cloudQueueClient        = cloudQueueClient;
     _queueNamesByMessageType = queueNamesByMessageType;
     _serializer          = serializer;
     _deserializerFactory = deserializerFactory;
     _queueRequestOptionsByMessageType = queueRequestOptionsByMessageType;
     _maxMessagesToDequeue             = maxMessagesToDequeue;
 }
Beispiel #3
0
        public ActiveMQServiceEndpointProvider(string serviceName,
                                               string brokerUri,
                                               IMessageSerializer serializer,
                                               IMessageDeserializerFactory deserializerFactory,
                                               List <Tuple <Type, AcknowledgementMode> > queueTypes,
                                               Func <Assembly, bool> assemblyFilter = null,
                                               Func <Type, bool> typeFilter         = null,
                                               Lazy <IConnection> sharedConnection  = null,
                                               string selector = null,
                                               Func <IDictionary, bool> propertyFilter = null,
                                               Func <TMessage, Dictionary <string, object> > propertyProvider = null,
                                               string userName = null,
                                               string password = null,
                                               Action <ConnectionFactory> connectionFactoryConfiguration = null,
                                               bool noLocal = false)
            : base(serviceName)
        {
            _serializer          = serializer;
            _deserializerFactory = deserializerFactory;
            _queueTypes          = queueTypes;
            _assemblyFilter      = assemblyFilter;
            _typeFilter          = typeFilter;
            _selector            = selector;
            _propertyFilter      = propertyFilter;
            _propertyProvider    = propertyProvider;
            _noLocal             = noLocal;

            if (string.IsNullOrEmpty(brokerUri) && sharedConnection == null)
            {
                throw new InvalidOperationException(string.Format("For service endpoint '{0}', please specify a brokerUri to connect to. To do this you can use either ConnectToBroker() per endpoint, or WithActiveMQSharedConnectionScope() to share a connection across multiple endpoints.", serviceName));
            }

            if (sharedConnection == null)
            {
                ConnectionFactory endpointConnectionFactory = new ConnectionFactory(brokerUri, ConnectionClientId.CreateWithSuffix(string.Format("{0}.Endpoint", serviceName)))
                {
                    CopyMessageOnSend = false
                };
                ConnectionFactory endpointClientConnectionFactory = new ConnectionFactory(brokerUri, ConnectionClientId.CreateWithSuffix(string.Format("{0}.EndpointClient", serviceName)))
                {
                    CopyMessageOnSend = false
                };

                if (connectionFactoryConfiguration != null)
                {
                    connectionFactoryConfiguration(endpointConnectionFactory);
                    connectionFactoryConfiguration(endpointClientConnectionFactory);
                }

                _endpointConnection       = endpointConnectionFactory.CreateLazyConnection(userName, password);
                _endpointClientConnection = endpointClientConnectionFactory.CreateLazyConnection(userName, password);
            }
            else
            {
                _endpointConnection       = sharedConnection;
                _endpointClientConnection = sharedConnection;
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public TcpMessageListener(ITcpClientFactory tcpClientFactory,
            IMessageDeserializerFactory messageDeserializerFactory, MessageEventDispatcher messageDispatcher)
        {
            _tcpClientFactory = tcpClientFactory;
            _messageDeserializerFactory = messageDeserializerFactory;
            _messageDispatcher = messageDispatcher;

            _clientThread = new Thread(ClientThread) {IsBackground = true};
        }
 public RabbitMQServiceEndpointProvider(string serviceName, string brokerUri, IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory, Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null)
     : base(serviceName)
 {
     _brokerUri           = brokerUri;
     _serializer          = serializer;
     _deserializerFactory = deserializerFactory;
     _typeFilter          = typeFilter ?? (type => true);
     _assemblyFilter      = assemblyFilter ?? (assembly => true);
 }
Beispiel #6
0
 public NetMqServiceEndpointProvider(string serviceName, string address, int port,
                                     IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory,
                                     Func <Assembly, bool> assemblyFilter, Func <Type, bool> typeFilter)
     : base(serviceName)
 {
     _serializer          = serializer;
     _deserializerFactory = deserializerFactory;
     _assemblyFilter      = assemblyFilter;
     _typeFilter          = typeFilter;
     _requestAddress      = string.Format("{0}:{1}", address, port + 0);
     _responseAddress     = string.Format("{0}:{1}", address, port + 1);
     _commandAddress      = string.Format("{0}:{1}", address, port + 2);
     _eventAddress        = string.Format("{0}:{1}", address, port + 3);
 }
        public void Test_CreationOfServiceEndpoint_InvalidDeserializerFactory()
        {
            var serializer = Mock.Of <IMessageSerializer>();
            IMessageDeserializerFactory deserializerFactory = null;

            Assert.Throws(
                typeof(ArgumentNullException),
                () => new AzureStorageQueueServiceEndpointProvider <ITestServiceMessage, TestMessage, TestCommand, TestEvent, TestRequest, TestResponse>(
                    TEST_SERVICE_NAME,
                    null,
                    _cloudQueueClientFixture.Client,
                    serializer,
                    deserializerFactory));
        }
        public NatsServiceEndpointProvider(NatsEndpointSettings <TMessage> settings, IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory, Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null, Func <IDictionary <string, string>, bool> propertyFilter = null, Func <TMessage, Dictionary <string, string> > propertyProvider = null)
            : base(settings.ServiceName)
        {
            _serializer          = serializer;
            _deserializerFactory = deserializerFactory;
            _assemblyFilter      = assemblyFilter;
            _typeFilter          = typeFilter;
            _propertyFilter      = propertyFilter;
            _propertyProvider    = propertyProvider;

            if (string.IsNullOrEmpty(settings.Connection?.Url))
            {
                throw new InvalidOperationException(string.Format("For service endpoint '{0}', please specify a broker URL to connect to.", settings.ServiceName));
            }

            _connection = SharedConnectionFactory.Get(settings.Connection.Url, settings.Connection.IsShared);
        }
Beispiel #9
0
 public static MessageSource <TMessage> Create <TMessage, TServiceMessage>(
     KafkaConfiguration kafkaConfiguration,
     KafkaSourceConfiguration sourceConfiguration,
     string topic,
     IMessageDeserializerFactory deserializerFactory,
     Func <Dictionary <string, string>, bool> propertyFilter,
     Func <Assembly, bool> assemblyFilter = null,
     Func <Type, bool> typeFilter         = null)
     where TMessage : class
     where TServiceMessage : class
 {
     return(new MessageSource <TMessage>(
                kafkaConfiguration,
                sourceConfiguration,
                topic,
                deserializerFactory.Create <TMessage, TServiceMessage>(assemblyFilter, typeFilter),
                propertyFilter));
 }
        public AzureStorageQueueFluentConfigTest()
        {
            _messageSerializer = new Mock <IMessageSerializer>().Object;
            // TODO Figure out how to mock the generic Create method
            var TestCommandDeserializerMock = new Mock <IMessageDeserializer <TestCommand1> >();

            TestCommandDeserializerMock.SetReturnsDefault <TestCommand1>(new TestCommand1());
            TestCommandDeserializerMock.Setup(x => x.GetTypeName()).Returns(typeof(TestCommand1).Name);
            var messageDeserializerFactoryMock = new Mock <IMessageDeserializerFactory>();

            messageDeserializerFactoryMock.Setup(x => x.Create <TestCommand1, TestMessage>(
                                                     It.Is <Func <Assembly, bool> >(null),
                                                     It.Is <Func <Type, bool> >(null)))
            .Returns(
                Obvs.Configuration.MessageTypes.Get <TestCommand1, TestMessage>(null, null)
                .Select(type => type.MakeGenericType(type))
                .Select(genericDeserializer => Activator.CreateInstance(genericDeserializer) as IMessageDeserializer <TestCommand1>));
            _messageDeserializerFactory = new TestMessageDeserializerFactory();
        }
 public static MessageSource <TMessage> CreateSource <TMessage, TServiceMessage>(
     Lazy <IConnection> lazyConnection,
     string destination,
     DestinationType destinationType,
     IMessageDeserializerFactory deserializerFactory,
     Func <IDictionary, bool> propertyFilter,
     Func <Assembly, bool> assemblyFilter = null,
     Func <Type, bool> typeFilter         = null,
     string selector          = null,
     AcknowledgementMode mode = AcknowledgementMode.AutoAcknowledge)
     where TMessage : class
     where TServiceMessage : class
 {
     return(new MessageSource <TMessage>(
                lazyConnection,
                deserializerFactory.Create <TMessage, TServiceMessage>(assemblyFilter, typeFilter),
                CreateDestination(destination, destinationType),
                mode, selector, propertyFilter));
 }
        public AzureServiceBusEndpointProvider(string serviceName, IMessagingFactory messagingFactory, IMessageSerializer messageSerializer, IMessageDeserializerFactory messageDeserializerFactory, List <MessageTypeMessagingEntityMappingDetails> messageTypePathMappings, Func <Assembly, bool> assemblyFilter, Func <Type, bool> typeFilter, MessagePropertyProviderManager <TMessage> messagePropertyProviderManager, IMessageOutgoingPropertiesTable messageOutgoingPropertiesTable)
            : base(serviceName)
        {
            if (messagingFactory == null)
            {
                throw new ArgumentNullException(nameof(messagingFactory));
            }
            if (messageSerializer == null)
            {
                throw new ArgumentNullException(nameof(messageSerializer));
            }
            if (messageDeserializerFactory == null)
            {
                throw new ArgumentNullException(nameof(messageDeserializerFactory));
            }
            if (messageTypePathMappings == null)
            {
                throw new ArgumentNullException(nameof(messageTypePathMappings));
            }
            if (messageTypePathMappings.Count == 0)
            {
                throw new ArgumentException("An empty set of path mappings was specified.", nameof(messageTypePathMappings));
            }
            if (messagePropertyProviderManager == null)
            {
                throw new ArgumentNullException(nameof(messagePropertyProviderManager));
            }
            if (messageOutgoingPropertiesTable == null)
            {
                throw new ArgumentNullException(nameof(messageOutgoingPropertiesTable));
            }

            _messageSerializer          = messageSerializer;
            _messageDeserializerFactory = messageDeserializerFactory;
            _assemblyFilter             = assemblyFilter;
            _typeFilter = typeFilter;
            _messageTypePathMappings        = messageTypePathMappings;
            _messagePropertyProviderManager = messagePropertyProviderManager;
            _messageOutgoingPropertiesTable = messageOutgoingPropertiesTable;

            _messagingEntityFactory = new MessagingEntityFactory(messagingFactory, messageTypePathMappings);
        }
        public RabbitMQServiceEndpointProvider(string serviceName, string brokerUri, IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory, Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null)
            : base(serviceName)
        {
            _brokerUri           = brokerUri;
            _serializer          = serializer;
            _deserializerFactory = deserializerFactory;
            _typeFilter          = typeFilter ?? (type => true);
            _assemblyFilter      = assemblyFilter ?? (assembly => true);

            _connection = new Lazy <IConnection>(() =>
            {
                var connectionFactory = new ConnectionFactory
                {
                    Uri = new Uri(brokerUri),
                    AutomaticRecoveryEnabled = true,
                };
                var conn = connectionFactory.CreateConnection();
                return(conn);
            }, LazyThreadSafetyMode.ExecutionAndPublication);
        }
        public EventStoreServiceEndpointProvider(string serviceName, EventStoreConfiguration configuration,
                                                 IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory,
                                                 Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null,
                                                 Func <Dictionary <string, string>, bool> propertyFilter        = null,
                                                 Func <TMessage, Dictionary <string, string> > propertyProvider = null,
                                                 List <Tuple <string, Type> > projectionStreams = null,
                                                 Lazy <IEventStoreConnection> sharedConnection  = null)
            : base(serviceName)
        {
            _configuration       = configuration;
            _serializer          = serializer;
            _deserializerFactory = deserializerFactory;
            _assemblyFilter      = assemblyFilter;
            _typeFilter          = typeFilter;
            _propertyFilter      = propertyFilter;
            _propertyProvider    = propertyProvider;
            _sharedConnection    = sharedConnection;
            _projectionStreams   = projectionStreams ?? new List <Tuple <string, Type> >();

            if (sharedConnection == null && string.IsNullOrEmpty(_configuration?.ConnectionString))
            {
                throw new InvalidOperationException(string.Format("For service endpoint '{0}', please specify a eventstore connection string to connect to. To do this you can use ConnectToEventStore() per endpoint", serviceName));
            }
        }
        public KafkaServiceEndpointProvider(string serviceName,
                                            KafkaConfiguration kafkaConfiguration, KafkaSourceConfiguration sourceConfiguration,
                                            KafkaProducerConfiguration producerConfiguration,
                                            IMessageSerializer serializer, IMessageDeserializerFactory deserializerFactory,
                                            Func <Dictionary <string, string>, bool> propertyFilter,
                                            Func <TMessage, Dictionary <string, string> > propertyProvider,
                                            Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null)
            : base(serviceName)
        {
            _kafkaConfiguration    = kafkaConfiguration;
            _sourceConfiguration   = sourceConfiguration ?? new KafkaSourceConfiguration();
            _producerConfiguration = producerConfiguration ?? new KafkaProducerConfiguration();
            _serializer            = serializer;
            _deserializerFactory   = deserializerFactory;
            _assemblyFilter        = assemblyFilter;
            _typeFilter            = typeFilter;
            _propertyFiter         = propertyFilter;
            _propertyProvider      = propertyProvider;

            if (string.IsNullOrEmpty(_kafkaConfiguration?.SeedAddresses))
            {
                throw new InvalidOperationException(string.Format("For service endpoint '{0}', please specify a kafkaUri to connect to. To do this you can use ConnectToKafka() per endpoint", serviceName));
            }
        }
Beispiel #16
0
 public static MessageSource <TMessage> CreateSource <TMessage, TServiceMessage>(string brokerUri, string routingKeyPrefix, string serviceName, IMessageDeserializerFactory deserializerFactory, Lazy <IConnection> connection, Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null, string selector = null)
     where TServiceMessage : class
     where TMessage : class
 {
     return(new MessageSource <TMessage>(
                connection,
                deserializerFactory.Create <TMessage, TServiceMessage>(assemblyFilter, typeFilter),
                serviceName,
                routingKeyPrefix));
 }
Beispiel #17
0
 public static MessageSource <TMessage> Create <TMessage, TServiceMessage>(Lazy <IEventStoreConnection> lazyConnection, string streamName, IMessageDeserializerFactory deserializerFactory,
                                                                           Func <Dictionary <string, string>, bool> propertyFilter, Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null)
     where TMessage : class
     where TServiceMessage : class
 {
     return(new MessageSource <TMessage>(
                lazyConnection,
                streamName,
                deserializerFactory.Create <TMessage, TServiceMessage>(assemblyFilter, typeFilter),
                propertyFilter));
 }