ruby-amqp / hutch

A system for processing messages from RabbitMQ.
https://gocardless.com/blog/hutch-inter-service-communication-with-rabbitmq/
MIT License
855 stars 137 forks source link

Hutch.publish returning (undefined method `publish' for nil:NilClass) #351

Closed jnarowski closed 4 years ago

jnarowski commented 4 years ago

It looks like since hutch is not creating the broker needed to publish info in 1.0.0 gem.

Here's what I am running: Hutch.connect({}, mq_username: 'xxx', mq_password: 'xxxx', mq_host: 'localhost', mq_port: 5672) Hutch.publish('queue', {id: 1})

=> 2.6.1 :021 > Hutch.publish Traceback (most recent call last):1: from (irb):21 NoMethodError (undefined method `publish' for nil:NilClass)

It looks like since it's already connected, the @broker isn't getting properly initialized?

I will be running hutch from the command line, and separately using Hutch.publish within my app to publish messages.

michaelklishin commented 4 years ago

I cannot reproduce. Consider providing a more detailed set of steps.

2.7.1 :005 > Hutch.connect
 => nil
2.7.1 :006 > Hutch.publish('queue', {id: 1})
 => #<Bunny::Exchange:0x00007f80921a7b00 @channel=#<Bunny::Channel:940 @id=1 @connection=#<Bunny::Session:0x6e0 guest@127.0.0.1:5672, vhost=/, addresses=[127.0.0.1:5672]>> @open=true, @name="hutch", @type="topic", @options={:queue=>"hutch", :nowait=>false, :durable=>true}, @durable=true, @auto_delete=nil, @internal=nil, @arguments=nil, @bindings=#<Set: {}>>

Running with BUNNY_LOG_LEVEL=debug will print every protocol method executed which can reveal a lot of useful information. Same goes for rabbitmq-diagnostics consume_event_stream.

Hutch's "singleton-oriented" design generally does not assume concurrent access and concurrent publishing on a shared channel is not something that RabbitMQ clients including Bunny support.

michaelklishin commented 4 years ago

I should perhaps mention that if can run Hutch on the command line (so, in a separate process) and from another app of your own, then there will be no channel (or connection) sharing. In such case you run Hutch as a tool in one place but use it as a library in another. My guess is that it does not connect or at least does not connect successfully in one of the cases. Troubleshooting Networking and server logs can help as well as the aforementioned client logs.

jnarowski commented 4 years ago

It looks like you are using a yml config file? I was passing in the options and config manually, so maybe it only works if you are using a config file. I will try that route and verify.

I have tried this both in console and in the app within a publisher class. I'll dig in further and let you know.

Thanks for the awesome library and quick responses. I was using Sneakers for a while but it proved quite unreliable.

michaelklishin commented 4 years ago

@jnarowski Sneakers is a lot more powerful and complex compared to Hutch. I help maintain both, so reliability of Hutch is not a given 😆