<commit_before>require "../amqp"
require "signal"

COUNT = 20
EXCHANGE_NAME = "sender_receiver"
QUEUE_NAME = "sender_receiver"

conn = AMQP::Connection.new(AMQP::Config.new(logger_level: Logger::DEBUG))
puts "Started"

conn.on_close do |code, msg|
  puts "CONNECTION CLOSED: #{code} - #{msg}"
end

channel = conn.channel
channel.on_close do |code, msg|
  puts "CHANNEL CLOSED: #{code} - #{msg}"
end

exchange = channel.direct(EXCHANGE_NAME)
queue = channel.queue(QUEUE_NAME)
queue.bind(exchange, queue.name)
queue.subscribe do |msg|
  puts "Received msg (1): #{msg.body}"
  msg.ack
end
queue.subscribe do |msg|
  puts "Received msg (2): #{msg.body}"
  msg.ack
end

COUNT.times do
  msg = AMQP::Message.new("test message")
  exchange.publish(msg, QUEUE_NAME)
  sleep 0.1
end

Signal.trap(Signal::INT) do
  puts "Exiting..."
  conn.loop_break
end
conn.run_loop<commit_msg>use counter<commit_after>require "../amqp"
require "signal"

COUNT = 20
EXCHANGE_NAME = "sender_receiver"
QUEUE_NAME = "sender_receiver"

conn = AMQP::Connection.new #(AMQP::Config.new(logger_level: Logger::DEBUG))
puts "Started"

conn.on_close do |code, msg|
  puts "CONNECTION CLOSED: #{code} - #{msg}"
end

channel = conn.channel
channel.on_close do |code, msg|
  puts "CHANNEL CLOSED: #{code} - #{msg}"
end

exchange = channel.direct(EXCHANGE_NAME)
queue = channel.queue(QUEUE_NAME)
queue.bind(exchange, queue.name)
queue.subscribe do |msg|
  puts "Received msg (1): #{msg.body}"
  msg.ack
end
queue.subscribe do |msg|
  puts "Received msg (2): #{msg.body}"
  msg.ack
end

COUNT.times do |idx|
  msg = AMQP::Message.new("test message: #{idx+1}")
  exchange.publish(msg, QUEUE_NAME)
  sleep 0.1
end

Signal.trap(Signal::INT) do
  puts "Exiting..."
  conn.loop_break
end
conn.run_loop
{'fraction_non_alphanumeric': 0.15034168564920272, 'fraction_numerical': 0.007403189066059226, 'mean_word_length': 4.837209302325581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3682812', 'n_tokens_mistral': 665, 'n_tokens_neox': 661, 'n_words': 163}