Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rq_insert(Index, Type, DocId, Doc)->
- DocNew = #{<<"i">>=>Index,<<"t">>=>Type,<<"id">>=>DocId,<<"doc">>=>Doc},
- PacketMQ = jiffy:encode(DocNew),
- %Z=zlib:open(),
- %zlib:deflateInit(Z),
- %CData=list_to_binary(zlib:deflate(Z, PacketMQ, finish)),
- %zlib:deflateEnd(Z),
- %zlib:close(Z),
- CData=zlib:gzip(PacketMQ),
- MQParam =gen_mod:get_module_opt(global, mod_custom_mam, rabbitmq,[{host,"localhost"}]),
- {ok, Connection} = amqp_connection:start(#amqp_params_network{
- host=proplists:get_value(host,MQParam,"localhost"),
- port=proplists:get_value(port,MQParam),
- username=proplists:get_value(username,MQParam),
- password=proplists:get_value(password,MQParam)
- }),
- Queue = proplists:get_value(queue,MQParam),
- {ok, Channel} = amqp_connection:open_channel(Connection),
- amqp_channel:call(Channel, #'queue.declare'{
- queue = Queue,
- durable = true
- }),
- amqp_channel:cast(Channel,
- #'basic.publish'{
- exchange = <<"">>,
- routing_key = Queue},
- #amqp_msg{
- props = #'P_basic'{delivery_mode = 2,content_encoding= <<"gzip">> },
- payload = CData
- }
- ),
- io:format(" [x] Sent 'Hello World!' ~p ~n",[size(CData)]),
- ok = amqp_channel:close(Channel),
- ok = amqp_connection:close(Connection).
- %https://www.rabbitmq.com/erlang-client-user-guide.html
- %https://github.com/pma/amqp/blob/master/lib/amqp/basic.ex#L68
Add Comment
Please, Sign In to add comment