system76 / bottle

Protobuf messages in a bottle
GNU General Public License v3.0
9 stars 6 forks source link

Add a publish/1 to Bottle #42

Closed doomspork closed 3 years ago

doomspork commented 3 years ago

Example usage:

    defp events_topic, do: Application.get_env(:assembly, :events_topic)

    defp bottle_message(resource, atom) do
        Bottle.Core.V1.Bottle.new(
          request_id: Bottle.RequestId.write(:http),
          resource: {atom, resource},
          source: "recognizer",
          timestamp: DateTime.to_unix(DateTime.utc_now())
        )
    end

    @decorate span(service: :bullhorn, type: :function)
    defp send_message(resource, atom) do
      message = bottle_message(resource, atom)

       Bottle.publish(events_topic(), message)

      {:ok, resource}
    end

We could also pull out the bottle_message/2 function and wrap up some of that for re-use between services.

Thoughts @system76/web-engineering?

doomspork commented 3 years ago
Bottle.publish(events_topic(), {type, resource}, source: "recognizer", request_id: Bottle.RequestId.write(:http))