Ejemplo n.º 1
0
        public static ICanAddEndpointOrLoggingOrCorrelationOrCreate <TMessage, TCommand, TEvent, TRequest, TResponse> WithActiveMQSharedConnectionScope <TMessage, TCommand, TEvent, TRequest, TResponse>(
            this ICanAddEndpoint <TMessage, TCommand, TEvent, TRequest, TResponse> canAddEndpoint,
            string brokerUri, string userName, string password,
            Action <ConnectionFactory> connectionFactoryConfig,
            Func <ICanAddEndpoint <TMessage, TCommand, TEvent, TRequest, TResponse>, ICanAddEndpointOrLoggingOrCorrelationOrCreate <TMessage, TCommand, TEvent, TRequest, TResponse> > endPointFactory)
            where TMessage : class
            where TCommand : class, TMessage
            where TEvent : class, TMessage
            where TRequest : class, TMessage
            where TResponse : class, TMessage
        {
            var connectionFactory = new ConnectionFactory(brokerUri, ConnectionClientId.CreateWithSuffix("Shared"))
            {
                CopyMessageOnSend = false // We never reuse our messages so don't need to clone when sending
            };

            connectionFactoryConfig(connectionFactory);

            var connection = !string.IsNullOrEmpty(userName)
                ? connectionFactory.CreateConnection(userName, password)
                : connectionFactory.CreateConnection();

            ActiveMQFluentConfigContext.SharedConnection = connection.GetLazyConnection();

            var result = endPointFactory(canAddEndpoint);

            ActiveMQFluentConfigContext.SharedConnection = null;
            return(result);
        }
Ejemplo n.º 2
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;
            }
        }