<commit_before># Hutch

A system for processing messages from RabbitMQ. Messages should be sent over
topic exchanges, and encoded with JSON.


## Defining Consumers

Consumers receive messages from a RabbitMQ queue. That queue may be bound to
one or more topics (represented by routing keys).

To create a consumer, include the `Hutch::Consumer` module in a class that
defines a `#process` method. `#process` should take a single argument, which
will be a `Message` object. The `Message` object encapsulates the message data,
along with any associated metadata. To access properties of the message, use
Hash-style indexing syntax:

```ruby
message[:id]  # => "02ABCXYZ"
```

To subscribe to a topic, pass a routing key to `consume` in the class
definition. To bind to multiple routing keys, simply pass extra routing keys
in as additional arguments. Refer to the [RabbitMQ docs on topic exchanges
][topic-docs] for more information about how to use routing keys. Here's an
example consumer:

```ruby
class FailedPaymentConsumer
  include Hutch::Consumer
  consume 'gc.ps.payment.failed'

  def process(message)
    mark_payment_as_failed(message[:id])
  end
end
```

[topic-docs]: http://www.rabbitmq.com/tutorials/tutorial-five-python.html


## Running Hutch

After installing the Hutch gem, you should be able to start it by simply
running `hutch` on the command line. `hutch` takes a number of options:

```console
$ hutch -h
usage: hutch [options]
        --rabbitmq-host HOST         Set the RabbitMQ host
        --rabbitmq-port PORT         Set the RabbitMQ port
        --rabbitmq-exchange PORT     Set the RabbitMQ exchange
        --require PATH               Require a Rails app or path<commit_msg>Update readme with new cmd line options<commit_after># Hutch

A system for processing messages from RabbitMQ. Messages should be sent over
topic exchanges, and encoded with JSON.


## Defining Consumers

Consumers receive messages from a RabbitMQ queue. That queue may be bound to
one or more topics (represented by routing keys).

To create a consumer, include the `Hutch::Consumer` module in a class that
defines a `#process` method. `#process` should take a single argument, which
will be a `Message` object. The `Message` object encapsulates the message data,
along with any associated metadata. To access properties of the message, use
Hash-style indexing syntax:

```ruby
message[:id]  # => "02ABCXYZ"
```

To subscribe to a topic, pass a routing key to `consume` in the class
definition. To bind to multiple routing keys, simply pass extra routing keys
in as additional arguments. Refer to the [RabbitMQ docs on topic exchanges
][topic-docs] for more information about how to use routing keys. Here's an
example consumer:

```ruby
class FailedPaymentConsumer
  include Hutch::Consumer
  consume 'gc.ps.payment.failed'

  def process(message)
    mark_payment_as_failed(message[:id])
  end
end
```

[topic-docs]: http://www.rabbitmq.com/tutorials/tutorial-five-python.html


## Running Hutch

After installing the Hutch gem, you should be able to start it by simply
running `hutch` on the command line. `hutch` takes a number of options:

```console
$ hutch -h
usage: hutch [options]
        --mq-host HOST               Set the RabbitMQ host
        --mq-port PORT               Set the RabbitMQ port
        --mq-exchange PORT           Set the RabbitMQ exchange
        --mq-api-port PORT           Set the RabbitMQ API port
        --mq-api-username USERNAME   Set the RabbitMQ API username
        --mq-api-password PASSWORD   Set the RabbitMQ API password
        --require PATH               Require a Rails app or path
{'fraction_non_alphanumeric': 0.07250755287009064, 'fraction_numerical': 0.0010985992859104642, 'mean_word_length': 3.4742014742014744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6141248', 'n_tokens_mistral': 1070, 'n_tokens_neox': 958, 'n_words': 470}