Skip to content

Instantly share code, notes, and snippets.

@jkauppinen
Last active November 24, 2016 12:06
Show Gist options
  • Save jkauppinen/33b680b087d3f4d4ff49a0182adfa70b to your computer and use it in GitHub Desktop.
Save jkauppinen/33b680b087d3f4d4ff49a0182adfa70b to your computer and use it in GitHub Desktop.
Code to identify possibly issue in MassTransit integer serialization
using NUnit.Framework;
using System;
using System.Threading.Tasks;
namespace MassTransit.SerializationTest
{
[TestFixture]
public class SerializationFixture
{
private IBusControl receiverBus;
private IBusControl senderBus;
public SerializationFixture()
{
senderBus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var uri = new Uri($"rabbitmq://localhost/");
var host = cfg.Host(uri, hostAddress =>
{
hostAddress.Username("guest");
hostAddress.Password("guest");
hostAddress.Heartbeat(15);
});
});
receiverBus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var uri = new Uri($"rabbitmq://localhost/");
var host = cfg.Host(uri, hostAddress =>
{
hostAddress.Username("guest");
hostAddress.Password("guest");
hostAddress.Heartbeat(15);
});
cfg.ReceiveEndpoint("MassTransit.SerializationTest", ec =>
{
ec.Consumer<MyMessageConsumer>(() => new MyMessageConsumer());
});
});
}
[SetUp]
public async Task Setup()
{
await senderBus.StartAsync();
await receiverBus.StartAsync();
}
[Test]
public async Task PublishTest()
{
MyMessage message = new MyMessage();
await senderBus.Publish(message);
await Task.Delay(2000);
Assert.IsTrue(true);
}
}
public class MyMessageConsumer : IConsumer<MyMessage>
{
public Task Consume(ConsumeContext<MyMessage> context)
{
// Let consumer fail so that we can see message in error queue
throw new NotImplementedException();
}
}
public class MyMessage
{
public int Int { get; set; }
public long Long { get; set; }
public ulong Ulong { get; set; }
public ushort Ushort { get; set; }
public short Short { get; set; }
public byte Byte { get; set; }
public sbyte Sbyte { get; set; }
public float Float { get; set; }
public double Double { get; set; }
public decimal Decimal { get; set; }
public char Char { get; set; }
public char String { get; set; }
public bool Bool { get; set; }
public object Object { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment