Conduit v0.12.10 Conduit.Plug.Wrap View Source
Plug to help wrap headers and fields into the message body
This can be helpful if your broker doesn’t support message headers natively.
By default this plug will update the body of the message to:
%{
"headers" => message.headers,
"fields" => %{}, # message_id, correlation_id, etc.
"body" => message.body
}
If you want a different wrapping structure for the message, you can pass the the
:wrap_fn
option. The wrap function should accept a message, the fields, the headers,
and body. The return value should be a message.
Examples
iex> alias Conduit.Message
iex> defmodule MyPipeline do
iex> use Conduit.Plug.Builder
iex> plug Conduit.Plug.Wrap
iex> end
iex>
iex> message =
iex> %Message{}
iex> |> Message.put_correlation_id("1")
iex> |> Message.put_header("foo", "bar")
iex> |> Message.put_body(%{})
iex> |> MyPipeline.run()
iex> message.body
%{
"headers" => %{
"foo" => "bar"
},
"fields" => %{
"correlation_id" => "1"
},
"body" => %{}
}
iex> alias Conduit.Message
iex> defmodule MyOtherPipeline do
iex> use Conduit.Plug.Builder
iex> plug Conduit.Plug.Wrap, wrap_fn: fn message, fields, headers, body ->
iex> body =
iex> body
iex> |> Map.put("meta", fields)
iex> |> put_in(["meta", "headers"], headers)
iex>
iex> Conduit.Message.put_body(message, body)
iex> end
iex> end
iex>
iex> message =
iex> %Message{}
iex> |> Message.put_correlation_id("1")
iex> |> Message.put_header("foo", "bar")
iex> |> Message.put_body(%{})
iex> |> MyOtherPipeline.run()
iex> message.body
%{
"meta" => %{
"correlation_id" => "1",
"headers" => %{
"foo" => "bar"
},
}
}
Link to this section Summary
Functions
Puts headers and fields into the body of the message
Callback implementation for Conduit.Plug.init/1
Callback implementation for Conduit.Plug.run/2
Link to this section Functions
Puts headers and fields into the body of the message
Callback implementation for Conduit.Plug.init/1
.
Callback implementation for Conduit.Plug.run/2
.