private IMessagePublisher <T> CreatePublisher <T>(Lazy <IConnection> connection, string destination) where T : class, TMessage { List <Tuple <Type, AcknowledgementMode> > queueTypes; if (TryGetMultipleQueueTypes <T>(out queueTypes)) { var topicTypes = MessageTypes.Get <T, TServiceMessage>().Where(type => queueTypes.All(qt => qt.Item1 != type)); var topicPublisher = new MessagePublisher <T>(connection, new ActiveMQTopic(destination), _serializer, _propertyProvider, Scheduler.Default); var topicPublishers = topicTypes.Select(tt => new KeyValuePair <Type, IMessagePublisher <T> >(tt, topicPublisher)); var queuePubishers = queueTypes.Select(qt => new KeyValuePair <Type, IMessagePublisher <T> >(qt.Item1, new MessagePublisher <T>( connection, new ActiveMQQueue(GetTypedQueueName(destination, qt.Item1)), _serializer, _propertyProvider, Scheduler.Default))); return(new TypeRoutingMessagePublisher <T>(topicPublishers.Concat(queuePubishers))); } return(DestinationFactory.CreatePublisher <T>(connection, destination, GetDestinationType <T>(), _serializer, _propertyProvider)); }
public void TestThatCorrectMessageTypesAreFound() { IEnumerable <Type> types = MessageTypes.Get <IMessage, ITestServiceMessage>(assembly => assembly.FullName.Contains("Obvs.Tests")).ToArray(); Assert.That(types.Any()); Assert.That(types.Contains(typeof(TestMessage1))); Assert.That(types.Contains(typeof(TestMessage2))); }
public IEnumerable <IMessageDeserializer <TMessage> > Create <TMessage, TServiceMessage>(Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null) where TMessage : class where TServiceMessage : class { return(MessageTypes.Get <TMessage, TServiceMessage>(assemblyFilter, typeFilter) .Select(type => typeof(ProtoBufMessageDeserializer <>).MakeGenericType(type)) .Select(deserializerGeneric => Activator.CreateInstance(deserializerGeneric) as IMessageDeserializer <TMessage>) .ToArray()); }
public IEnumerable <IMessageDeserializer <TMessage> > Create <TMessage, TServiceMessage>( Func <Assembly, bool> assemblyFilter = null, Func <Type, bool> typeFilter = null ) where TMessage : class where TServiceMessage : class { var messageTypes = MessageTypes.Get <TMessage, TServiceMessage>(assemblyFilter, typeFilter); return(messageTypes.Select(deserializerGeneric => new TestDeserializer <TMessage>()) .ToArray()); }