Anybody successfully got MassTransit working with AppHarbor and CloudAMQP?
I am having a bear of a time with it.
I have the publisher (the web site) sending messages, but the server (a background worker) does not appear to be picking them up.
One of the things that concern me is that MT requires the rabbitmq scheme whereas CloudAMQP sets the scheme to amqp.
I am swapping the scheme (from amqp to rabbitmq) when configuring the bus and noticed the scheme in the addresses of the message is rabbitmq, which makes sense, since I replaced them. But I am wondering if they have to be amqp for the server to pick them up?
Here is a simple message that I have sent, it got to RabbitMQ but server is not picking it up.
message_id: 08cf2cbc-5b4f-14dd-1231-381f8b520000
delivery_mode: 2
headers:
Content-Type: application/vnd.masstransit+json
Payload
614 bytes
Encoding: string
{
"destinationAddress": "rabbitmq://98eabe2a-aae8-464c-8555-855518dd87d0_apphb.com:*********@lemur.cloudamqp.com/98eabe2a-aae8-464c-8555-855518dd87d0_apphb.com/Messages.Product:ProductCreatedEvent",
"headers": {},
"message": {
"id": "dd6ecfaa-60d2-4cd4-8cd6-a08a00e872fb"
},
"messageType": [
"urn:message:Messages.Product:ProductCreatedEvent"
],
"retryCount": 0,
"sourceAddress": "rabbitmq://98eabe2a-aae8-464c-8555-855518dd87d0_apphb.com:**********@lemur.cloudamqp.com/98eabe2a-aae8-464c-8555-855518dd87d0_apphb.com/enterprise_web"
}
Thanks, Joe
Edit: Thanks Carl pointing out the passwords in the url
Edit: To let anyone else thinking about using MassTransit with CloudAMQP, you may want to look into EasyNetQ instead. Not taking anything away from MassTransit, its a great project. The problem when using it with a service like CloudAMQP that charges data usage per month, is that MassTransit uses polling to check for messages, instead of subscribing to them (at least in the last version I was working with 2.1.1). This polling will eat into your data usage even though you may not be publishing messages.
Well it is in fact possible.
Come to find out, it was all part of the configuration of the background worker on appharbor.
Once that got worked out the background worker started staying "alive" and consuming messages. The issue revolved around app.config vs myworker.exe.config and config transforms. Once I realized it was a config problem this link helped out. App.config transformation for appharbor background workers
You have to swap out the amqp scheme for rabbitmq but that is not to bad. Here is my bus configuration for the background worker:
log.Info("Configuring MassTransit");
var rabbitUrl = ConfigurationManager.AppSettings["CLOUDAMQP_URL"];
var bus = ServiceBusFactory.New(sbc =>
{
// configure for log4net
sbc.UseLog4Net();
// configure the bus
sbc.UseRabbitMq();
sbc.UseRabbitMqRouting();
sbc.ReceiveFrom(String.Format("{0}/server", rabbitUrl.Replace("amqp://", "rabbitmq://"))); // need to swap the scheme for masstransit
// finds all the consumers in the container and register them with the bus
sbc.Subscribe(x => x.LoadFrom(container));
sbc.BeforeConsumingMessage(() =>
{
var session = container.GetInstance<ISessionFactory>().OpenSession();
CurrentSessionContext.Bind(session);
});
sbc.AfterConsumingMessage(() =>
{
var sessionFactory = container.GetInstance<ISessionFactory>();
if (CurrentSessionContext.HasBind(sessionFactory) == false) return;
var session = CurrentSessionContext.Unbind(sessionFactory);
if (session != null)
{
session.Dispose();
}
});
var results = sbc.Validate();
if (results.Any())
{
throw new Exception("MassTransit may not be setup correctly. Review validate results");
}
});
// finally inject the bus into the container
container.Inject(bus);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With