UofFeed is a library designed to connect to BetRadar AMQP queues. It provides a simple mechanism for consuming and processing messages by defining a set of rules for mapping messages from XML format to predefined Elixir structures.
If available in Hex, the package can be installed
by adding uof_feed
to your list of dependencies in mix.exs
:
def deps do
[
{:uof_feed, "~> 0.1.0"}
]
end
After installing the dependency, copy the following configuration into your config/config.ex
.
This contains default values that can be overridden, but necessary to correctly compile the library.
config: :uof_feed,
amqp_environment: :integration,
amqp_handler: UofFeed.Handlers.XMLInspect,
pubsub_topic: "uof-feed-messages",
start_amqp_client?: true,
amqp_token: "YOUR TOKEN",
amqp_bookmaker_id: 1
amqp_environment
- used to determine API URL, default::integration
; for specifics checkUofFeed.AMQP.Config.amqp_opts/4
,amqp_handler
- handler used to process the messages from XML, default:UofFeed.Handlers.XMLInspect
; for more check Message handlersstart_amqp_client?
- IMPORTANT: must be set totrue
to startUofFeed.AMQP.Client
GenServer,amqp_token
- your API token to access e.g. BetRadar API,amqp_bookmaker_id
- the ID of bookmaker,pubsub_topic
-Phoenix.PubSub
topic to which processed messages should be broadcasted
To set up AMQP connection and start consuming the messages you can use UofFeed.connect_and_subscribe/4
function.
It allows you to specify a simple message handler as function with arity of 2.
It's encouraged to use this function in :dev
environment as means of verification or simple testing.
For production, it's recommended to use UofFeed.AMQP.Client
and appropriate message handler.
Required variables
environment = :integration
token = "YOUR TOKEN"
port = 5671
handler = fn xml, _meta -> IO.inspect(xml) end
UofFeed.connect_and_subscribe(:integration, token, port, handler)
handler = fn xml, _meta ->
xml |> UofFeed.Mapper.call() |> IO.inspect()
end
UofFeed.connect_and_subscribe(:integration, token, port, handler)
UofFeed
library implements mapping of the following XML messages from BetRadar:
- FixtureChange
- OddsChange
- BetStop
- BetCancel
- BetSettlement
Notice
There are some fields not fully mapped, e.g. UofFeed.Messages.SportEventStatus
, expect such cases to gradually disappear.
To accommodate different needs UofFeed
library provides a set of default message handlers.
To configure message handler for UOF.AMQP.Client
use :uof_feed, :amqp_handler
in the Configuration
UofFeed.Handlers.XMLInspect
- default message handler, logs raw XML into the logs,UofFeed.Handlers.DataSchemaInspect
- map XML to Elixir structures, log the structures (or error) into the logs,UofFeed.Handlers.PubSub
- map XML to Elixir structures and publish (usingPhoenix.PubSub
) results on specific topic (default:uof-feed-messages
), check Configuration on how to change it depending on your needs
If none of the available Message handlers meets your expectations you are free to implement your own.
To make it easier UofFeed
library provides handler behaviour, UofFeed.Handlers.Behaviour
Custom handler
defmodule Myapp.MyCustomHandler do
use UofFeed.Handlers.Behaviour
def handle_message(xml) do
# your code here
:ok
end
end
In the config:
config :uof_feed, amqp_handler: Myapp.MyCustomHandler
- Map all existing messages
- Expand mapping to include all tags, e.g. add
statistics
andperiod_scores
toSportEventStatus
mapping - Add a Phoenix LiveView application to provide dashboard features
- Improve application resiliency and error reporting
- Add more message handlers
- Expand list of providers
- Add metrics