Created
June 23, 2018 16:55
-
-
Save yosiat/2ff3b51c50252261ced88f3ab447a77c to your computer and use it in GitHub Desktop.
Sneakers RPC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sneakers' | |
require 'sneakers/runner' | |
require 'byebug' | |
require 'oj' | |
class RpcServer | |
include Sneakers::Worker | |
from_queue 'downloads' | |
def work_with_params(deserialized_msg, delivery_info, metadata) | |
publish({ "a" => 1 }, { | |
to_queue: metadata[:reply_to], | |
correlation_id: metadata[:correlation_id], | |
content_type: metadata[:content_type] | |
}) | |
ack! | |
end | |
end | |
# Werid that we need to do this, but this allows to use Oj | |
Sneakers::ContentType.register( | |
content_type: 'application/json', | |
deserializer: ->(payload) { Oj.load(payload) }, | |
serializer: ->(payload) { Oj.dump(payload) }, | |
) | |
Sneakers.configure({ | |
threads: 1, # for easy debugging | |
exchange: "" # USE default exchange instead of sneakers exchange | |
}) | |
# Default is debug =X | |
Sneakers.logger.level = Logger::INFO | |
Sneakers::Runner.new([RpcServer]).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment