Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

trying to capture a rabbitmq issue

  • Loading branch information...
commit e559cdba4f24cf630a54004612cbf1b50aa969ef 1 parent 1c0b27f
@drusellers drusellers authored
View
67 src/MassTransit/Endpoints.cs
@@ -0,0 +1,67 @@
+namespace MassTransit
+{
+ using System;
+ using Builders;
+ using EndpointConfigurators;
+ using Transports;
+
+ /// <summary>
+ /// This is a static singleton instance of an EndpointFactory. While it goes
+ /// against my very soul, it is here to ensure consistent usage of MassTransit
+ /// as a singleton. It is highly recommended that <see cref="ServiceBusFactory.New"/> be
+ /// used instead and the application maintain the reference to the EndpointFactory.
+ /// </summary>
+ public static class Endpoints
+ {
+ //look at all of this room for activities
+ // <activity zone>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ // <end of activity zone>
+
+ static IEndpointFactory _endpointFactory;
+
+ public static void Initialize(Action<EndpointFactoryBuilder> configure)
+ {
+ var settings = new EndpointFactoryDefaultSettings();
+ var epf = new EndpointFactoryBuilderImpl(settings);
+ configure(epf);
+ _endpointFactory = epf.Build();
+
+
+ }
+
+ public static IEndpoint GetEndpoint(string uri)
+ {
+ return GetEndpoint(new Uri(uri));
+ }
+
+ public static IEndpoint GetEndpoint(Uri uri)
+ {
+ return _endpointFactory.CreateEndpoint(uri);
+ }
+
+ // "Hey I never asked you. Do you like guacamole?"
+ }
+}
View
1  src/MassTransit/MassTransit.csproj
@@ -350,6 +350,7 @@
<Compile Include="EndpointLoggerExtensions.cs" />
<Compile Include="Context\EndpointObjectSender.cs" />
<Compile Include="Context\EndpointObjectSenderImpl.cs" />
+ <Compile Include="Endpoints.cs" />
<Compile Include="Exceptions\MessageNotConsumedException.cs" />
<Compile Include="Exceptions\MessageRetryLimitExceededException.cs" />
<Compile Include="Exceptions\RequestException.cs" />
View
1  ...sports/MassTransit.Transports.RabbitMq.Tests/MassTransit.Transports.RabbitMq.Tests.csproj
@@ -96,6 +96,7 @@
<Compile Include="Given_two_rabbitmq_buses_walk_into_a_bar.cs" />
<Compile Include="Request_Specs.cs" />
<Compile Include="Selective_Consumer_Specs.cs" />
+ <Compile Include="Should_not_consume_messages_early.cs" />
<Compile Include="TestFactory.cs" />
<Compile Include="Given_a_rabbitmq_bus.cs" />
<Compile Include="Given_a_rabbitmq_bus_with_vhost_mt_and_credentials.cs" />
View
93 src/Transports/MassTransit.Transports.RabbitMq.Tests/Should_not_consume_messages_early.cs
@@ -0,0 +1,93 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+// this file except in compliance with the License. You may obtain a copy of the
+// License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations under the License.
+namespace MassTransit.Transports.RabbitMq.Tests
+{
+ using System;
+ using System.Threading;
+ using NUnit.Framework;
+ using Serialization;
+ using Magnum.Extensions;
+
+ public class Should_not_consume_messages_early
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ using(createBus())
+ {
+ //setup bindings
+ }
+
+ Endpoints.Initialize(cfg=>
+ {
+ cfg.AddTransportFactory(new RabbitMqTransportFactory());
+ cfg.SetDefaultSerializer(new JsonMessageSerializer());
+ });
+
+ var ep = Endpoints.GetEndpoint("rabbitmq://localhost/bob");
+ for (int i = 0; i < 100; i++)
+ {
+ ep.Send(new RabbitMessage());
+ }
+
+ _i = 0;
+ }
+
+ ManualResetEvent _mre;
+ int _i = 0;
+
+ [Test]
+ public void Test()
+ {
+ _mre = new ManualResetEvent(false);
+
+ using(var bus = createBus())
+ {
+
+
+ _mre.WaitOne(5.Seconds());
+ }
+ }
+
+ IServiceBus createBus()
+ {
+ var sb = ServiceBusFactory.New(sbc =>
+ {
+ sbc.UseRabbitMq();
+ sbc.UseRabbitMqRouting();
+
+ sbc.ReceiveFrom("rabbitmq://localhost/bob");
+ sbc.Subscribe(subs =>
+ {
+ subs.Handler<RabbitMessage>(m =>
+ {
+ _i++;
+ Console.WriteLine("got it");
+ if(_i>=100)
+ {
+ _mre.Set();
+ Console.WriteLine(_i);
+ }
+
+ });
+ });
+ });
+ return sb;
+ }
+ }
+
+ public class RabbitMessage
+ {
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.