Raven MQ – The Real API

time to read 3 min | 589 words

Originally posted at 11/17/2010

This is now a passing test…

public class UntypedMessages : IDisposable
{
    private readonly RavenMqServer ravenMqServer;
    private readonly RavenConfiguration configuration;

    public UntypedMessages()
    {
        configuration = new RavenConfiguration
        {
            RunInMemory = true,
            AnonymousUserAccessMode = AnonymousUserAccessMode.All
        };
        ravenMqServer = new RavenMqServer(configuration);
    }

    [Fact]
    public void Can_get_message_from_client_connection()
    {
        using(var connection = new RavenMQConnection(
            new Uri(configuration.ServerUrl), 
            new IPEndPoint(IPAddress.Loopback, 8181)))
        {
            var manualResetEventSlim = new ManualResetEventSlim(false);
            OutgoingMessage msg = null;
            connection.Subscribe("/queues/abc", (context, message) =>
            {
                msg = message;
                manualResetEventSlim.Set();
            });

            WaitForSubscription();

            ravenMqServer.Queues.Enqueue(new IncomingMessage
            {
                Data = new byte[] {1, 2, 3},
                Queue = "/queues/abc"
            });

            manualResetEventSlim.Wait();

            Assert.Equal(new byte[]{1,2,3}, msg.Data);
        }
    }

    private void WaitForSubscription()
    {
        // not important
    }

    public void Dispose()
    {
        ravenMqServer.Dispose();
    }
}

Unlike the previous posts, which were more design and up front, this post shows working code. I am still not completely happy witht his, mostly because of the RavenMQConnection ctor parameters, but I can live with this for now.