public void AppendTo_sets_message_type_and_alternatives_for_a_versioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var property = MessageTypeProperty.CreateForMessageType( typeof( MyMessageV2 ), typeNameSerialiser ); var properties = new MessageProperties(); property.AppendTo( properties ); Assert.That( properties.Type, Is.EqualTo( typeNameSerialiser.Serialize( typeof( MyMessageV2 ) ) ) ); Assert.That( properties.Headers[ AlternativeMessageTypesHeaderKey ], Is.EqualTo( typeNameSerialiser.Serialize( typeof( MyMessage ) ) ) ); }
public void AppendTo_sets_message_type_and_alternatives_for_a_versioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var property = MessageTypeProperty.CreateForMessageType(typeof(MyMessageV2), typeNameSerialiser); var properties = new MessageProperties(); property.AppendTo(properties); Assert.Equal(properties.Type, typeNameSerialiser.Serialize(typeof(MyMessageV2))); Assert.Equal(properties.Headers[AlternativeMessageTypesHeaderKey], typeNameSerialiser.Serialize(typeof(MyMessage))); }
public void MessageTypeProperty_is_created_correctly_from_message_properties_for_versioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var properties = new MessageProperties {Type = typeNameSerialiser.Serialize( typeof( MyMessageV2 ) )}; var encodedAlternativeMessageTypes = Encoding.UTF8.GetBytes( typeNameSerialiser.Serialize( typeof( MyMessage ) ) ); properties.Headers.Add( AlternativeMessageTypesHeaderKey, encodedAlternativeMessageTypes ); var property = MessageTypeProperty.ExtractFromProperties( properties, typeNameSerialiser ); var messageType = property.GetMessageType(); Assert.That( messageType.Type, Is.EqualTo( typeof( MyMessageV2 ) ) ); }
public void MessageTypeProperty_is_created_correctly_from_message_properties_for_versioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var properties = new MessageProperties { Type = typeNameSerialiser.Serialize(typeof(MyMessageV2)) }; var encodedAlternativeMessageTypes = Encoding.UTF8.GetBytes(typeNameSerialiser.Serialize(typeof(MyMessage))); properties.Headers.Add(AlternativeMessageTypesHeaderKey, encodedAlternativeMessageTypes); var property = MessageTypeProperty.ExtractFromProperties(properties, typeNameSerialiser); var messageType = property.GetMessageType(); Assert.That(messageType.Type, Is.EqualTo(typeof(MyMessageV2))); }
public void The_default_queue_naming_convention_should_use_the_TypeNameSerializers_Serialize_method_then_an_underscore_then_the_subscription_id() { const string subscriptionId = "test"; var result = conventions.QueueNamingConvention(typeof(TestMessage), subscriptionId); result.ShouldEqual(TypeNameSerializer.Serialize(typeof(TestMessage)) + "_" + subscriptionId); }
public IMessagesMove AsType(Type messageType) { var typeNameSerializer = new TypeNameSerializer(); MessageType = typeNameSerializer.Serialize(messageType); return(this); }
public void Should_throw_exception_if_type_is_null() { // Arrange var serializer = new TypeNameSerializer(); // Action serializer.Serialize(null); }
public void MessageTypeProperty_is_created_correctly_from_message_properties_for_unversioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var properties = new MessageProperties {Type = typeNameSerialiser.Serialize( typeof( MyMessage ) )}; var property = MessageTypeProperty.ExtractFromProperties( properties, typeNameSerialiser ); var messageType = property.GetMessageType(); Assert.That( messageType.Type, Is.EqualTo( typeof( MyMessage ) ) ); }
public void AppendTo_sets_message_type_and_no_alternatives_for_an_unversioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var property = MessageTypeProperty.CreateForMessageType(typeof(MyMessage), typeNameSerialiser); var properties = new MessageProperties(); property.AppendTo(properties); Assert.That(properties.Type, Is.EqualTo(typeNameSerialiser.Serialize(typeof(MyMessage)))); Assert.That(properties.Headers.ContainsKey(AlternativeMessageTypesHeaderKey), Is.False); }
public void GetType_returns_first_available_alternative_if_message_type_unavailable() { var typeNameSerialiser = new TypeNameSerializer(); var v1 = typeNameSerialiser.Serialize(typeof(MyMessage)); var v2 = typeNameSerialiser.Serialize(typeof(MyMessageV2)); var vUnknown = v2.Replace("MyMessageV2", "MyUnknownMessage"); var alternativeTypes = string.Concat(v2, ";", v1); var encodedAlternativeTypes = Encoding.UTF8.GetBytes(alternativeTypes); var properties = new MessageProperties { Type = vUnknown }; properties.Headers.Add(AlternativeMessageTypesHeaderKey, encodedAlternativeTypes); var property = MessageTypeProperty.ExtractFromProperties(properties, typeNameSerialiser); var messageType = property.GetMessageType(); Assert.That(messageType.Type, Is.EqualTo(typeof(MyMessageV2))); }
public void Should_throw_exception_if_type_fullName_is_null() { // Arrange var type = Substitute.For <Type>(); type.FullName.Returns((string)null); var serializer = new TypeNameSerializer(); // Action serializer.Serialize(type); }
public void MessageTypeProperty_is_created_correctly_from_message_properties_for_unversioned_message() { var typeNameSerialiser = new TypeNameSerializer(); var properties = new MessageProperties { Type = typeNameSerialiser.Serialize(typeof(MyMessage)) }; var property = MessageTypeProperty.ExtractFromProperties(properties, typeNameSerialiser); var messageType = property.GetMessageType(); Assert.That(messageType.Type, Is.EqualTo(typeof(MyMessage))); }
private void CreateBus(Conventions conventions, IModel model) { bus = new RabbitBus( x => TypeNameSerializer.Serialize(x.GetType()), new JsonSerializer(), new MockConsumerFactory(), new MockConnectionFactory(new MockConnection(model)), new MockLogger(), CorrelationIdGenerator.GetCorrelationId, conventions ); }
public void Publish <T>(T message) where T : class { var properties = new MessageProperties(); properties.Type = typeNameSerializer.Serialize(message.GetType()); properties.MessageId = Guid.NewGuid().ToString(); //TODO: set correlation Id messages.Add(new MessageWithProperties { Message = message, Properties = properties }); }
private void CreateBus(IConventions conventions, IModel model) { var advancedBus = new RabbitAdvancedBus( new ConnectionConfiguration(), new MockConnectionFactory(new MockConnection(model)), TypeNameSerializer.Serialize, new JsonSerializer(), new MockConsumerFactory(), new MockLogger(), CorrelationIdGenerator.GetCorrelationId, new Conventions() ); bus = new RabbitBus( x => TypeNameSerializer.Serialize(x.GetType()), new MockLogger(), conventions, advancedBus ); }
public void GetType_throws_exception_if_all_types_unavailable() { var typeNameSerialiser = new TypeNameSerializer(); var v2 = typeNameSerialiser.Serialize(typeof(MyMessageV2)); var vUnknown1 = v2.Replace("MyMessageV2", "MyUnknownMessage"); var vUnknown2 = v2.Replace("MyMessageV2", "MyUnknownMessageV2"); var vUnknown3 = v2.Replace("MyMessageV2", "MyUnknownMessageV3"); var alternativeTypes = string.Concat(vUnknown2, ";", vUnknown1); var encodedAlternativeTypes = Encoding.UTF8.GetBytes(alternativeTypes); var properties = new MessageProperties { Type = vUnknown3 }; properties.Headers.Add(AlternativeMessageTypesHeaderKey, encodedAlternativeTypes); var property = MessageTypeProperty.ExtractFromProperties(properties, typeNameSerialiser); Assert.Throws <EasyNetQException>(() => property.GetMessageType()); }
public virtual void HandleConsumerError(ConsumerExecutionContext context, Exception exception) { Preconditions.CheckNotNull(context, "context"); Preconditions.CheckNotNull(exception, "exception"); try { Connect(); using (var model = connection.CreateModel()) { var errorExchange = DeclareErrorExchangeQueueStructure(model, context.Info.RoutingKey); var messageBody = CreateErrorMessage(context, exception); var properties = model.CreateBasicProperties(); properties.SetPersistent(true); properties.Type = TypeNameSerializer.Serialize(typeof(Error)); model.BasicPublish(errorExchange, context.Info.RoutingKey, properties, messageBody); } } catch (BrokerUnreachableException) { // thrown if the broker is unreachable during initial creation. logger.ErrorWrite("EasyNetQ Consumer Error Handler cannot connect to Broker\n" + CreateConnectionCheckMessage()); } catch (OperationInterruptedException interruptedException) { // thrown if the broker connection is broken during declare or publish. logger.ErrorWrite("EasyNetQ Consumer Error Handler: Broker connection was closed while attempting to publish Error message.\n" + string.Format("Message was: '{0}'\n", interruptedException.Message) + CreateConnectionCheckMessage()); } catch (Exception unexpecctedException) { // Something else unexpected has gone wrong :( logger.ErrorWrite("EasyNetQ Consumer Error Handler: Failed to publish error message\nException is:\n" + unexpecctedException); } }
public void Should_serialize_a_type_name() { var typeName = TypeNameSerializer.Serialize(typeof(string)); typeName.ShouldEqual(expectedTypeName); }
public void GetType_throws_exception_if_all_types_unavailable() { var typeNameSerialiser = new TypeNameSerializer(); var v2 = typeNameSerialiser.Serialize( typeof( MyMessageV2 ) ); var vUnknown1 = v2.Replace( "MyMessageV2", "MyUnknownMessage" ); var vUnknown2 = v2.Replace( "MyMessageV2", "MyUnknownMessageV2" ); var vUnknown3 = v2.Replace( "MyMessageV2", "MyUnknownMessageV3" ); var alternativeTypes = string.Concat( vUnknown2, ";", vUnknown1 ); var encodedAlternativeTypes = Encoding.UTF8.GetBytes( alternativeTypes ); var properties = new MessageProperties {Type = vUnknown3 }; properties.Headers.Add( AlternativeMessageTypesHeaderKey, encodedAlternativeTypes ); var property = MessageTypeProperty.ExtractFromProperties( properties, typeNameSerialiser ); Assert.Throws<EasyNetQException>( () => property.GetMessageType() ); }
public void GetType_returns_first_available_alternative_if_message_type_unavailable() { var typeNameSerialiser = new TypeNameSerializer(); var v1 = typeNameSerialiser.Serialize( typeof( MyMessage ) ); var v2 = typeNameSerialiser.Serialize( typeof( MyMessageV2 ) ); var vUnknown = v2.Replace( "MyMessageV2", "MyUnknownMessage" ); var alternativeTypes = string.Concat( v2, ";", v1 ); var encodedAlternativeTypes = Encoding.UTF8.GetBytes( alternativeTypes ); var properties = new MessageProperties {Type = vUnknown }; properties.Headers.Add( AlternativeMessageTypesHeaderKey, encodedAlternativeTypes ); var property = MessageTypeProperty.ExtractFromProperties( properties, typeNameSerialiser ); var messageType = property.GetMessageType(); Assert.That( messageType.Type, Is.EqualTo( typeof( MyMessageV2 ) ) ); }
public void Should_serialize_a_custom_type() { var typeName = TypeNameSerializer.Serialize(typeof(TypeNameSerializer)); typeName.ShouldEqual(expectedCustomTypeName); }
public void The_default_topic_naming_convention_should_use_the_TypeNameSerializers_Serialize_method() { var result = conventions.TopicNamingConvention(typeof(TestMessage)); result.ShouldEqual(TypeNameSerializer.Serialize(typeof(TestMessage))); }
public void The_default_rpc_routingkey_naming_convention_should_use_the_TypeNameSerializers_Serialize_method() { var result = conventions.RpcRoutingKeyNamingConvention(typeof(TestMessage)); result.ShouldEqual(TypeNameSerializer.Serialize(typeof(TestMessage))); }