Connection and Consumption setup

Connecting to LSports RabbitMQ

So you've started to implement LSports services via RMQ, great choice! Let's get your connection running with a few simple steps.

This guide is intended to provide a better understanding of how the LSports Support team works to resolve issues in a timely manner and with minimal effort on your part.

Step-by-step instructions:

• We recommend using our demo C# SDK to get you started with quick implementation, you can download the file from here:

SDK - C# - please be advised, if anything is missing on the SDK, you can rely on the Solutions section - it is updated regularly.

The following example refers to these credentials: Username: MyEmail Password: Passw0rd1234 Package: 102030 (You should use the credentials provided by LSports)

Note: All examples below are written in C#.

Should you choose to implement your own code, you will need to get the RMQ library Here.

Please be aware that LSports currently uses version 3.6.5.0

  1. Start off by making sure that your package is enabled by sending an API call as follows:

InPlay Package: https://inplay.lsports.eu/api/Package/EnablePackage?username=MyEmail&password=Passw0rd1234&packageid=102030

Prematch Package: https://prematch.lsports.eu/OddService/EnablePackage?username=MyEmail&password=Passw0rd1234&guid=guid-provided-by-LSports

Response:

<xs:schema>
  <xs:element name="Message">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Header">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:short" name="HttpStatusCode"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Body">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="Message"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Please know that you can also disable your package if you are in need of turning it off by changing the "EnablePackage" to "DisablePackage" as follows:

InPlay Package: https://inplay.lsports.eu/api/Package/DisablePackage?username=MyEmail&password=Passw0rd1234&packageid=102030

Prematch Package: https://prematch.lsports.eu/OddService/DisablePackage?username=MyEmail&password=Passw0rd1234&guid=guid-provided-by-LSports

If the package was already enabled/disabled then the message should contain "Value was already set". For any other status or error message, please recheck your credentials or contact us.

  1. Create a connection factory as follow:

ConnectionFactory connectionFactory = new ConnectionFactory
{
    HostName = "Described below",
    Port = 5672,
    UserName = "MyEmail",
    Password = "Passw0rd1234",
    AutomaticRecoveryEnabled = true,
    VirtualHost = "Customers", //Default value
    RequestedHeartbeat = 580,
    NetworkRecoveryInterval = TimeSpan.FromSeconds(1)
};
RMQ HostName:

InPlay: inplay-rmq.lsports.eu
PreMatch: prematch-rmq.lsports.eu
  1. Create a connection as follows:

IConnection connection = _connectionFactory.CreateConnection();
  1. Create a model as follows:

IModel model = connection.CreateModel();
  1. Configure the quality of service:

model.BasicQos(prefetchSize: 0, prefetchCount: 1000, global: false);
  1. Consume message:

EventingBasicConsumer consumer = new EventingBasicConsumer(model);
consumer.Received += (sender, eventArgs) =>
{
    // Deserialize message
    // Call method to handle deserialized message
};
  1. Start message consumption:

(make sure to type in your package ID using underscores ('_') as described) For example, if the package ID was “102030”

model.BasicConsume(queue: '_102030_', noAck: true, consumer: consumer)
  • From here you should be able to pull up your RMQ connection and start receiving Heartbeat messages.

Full Snapshot Request

As updates coming through RMQ to you are deltas only before you start consuming messages coming from LSports, you should request a snapshot of the data you should be receiving. You can do so by making an API call to the following:


Possible error types

Note: If the queue reaches 10000 unread/unpacked messages it will be automatically purged and your package will be disabled.

Most failed connection attempts occur due to incorrect credentials or incorrect connection details. Here are the most common errors and possible solutions:

"Connection failed" - Please check that the connection details i.e. Connection factory, RMQ host, VirtualHost are typed correctly. "Access refused"- Please check that your package is enabled and that the login credentials and package ID were typed correctly.

  • We do not recommend utilizing more than 1 consumer per feed (Prematch/InPlay), if you are insisting on using multiple consumers, be aware of the following:

  1. The messages will be received in a round-robin fashion, the data will be distributed equally among all existing consumers

  2. We have witnessed message loss while customers were using multiple consumers.

For an in-depth explanation of our data structure, you may continue reading our documentation. Now all you need to do is, to start ordering our sports data according to your specific needs.


Message Deserializing

The data you receive via RabbitMQ arrives as an array of bytes. The array of bytes has to be deserialized in order for it to become readable. The deserialization method depends on the format that you have selected to get the data in. If the format you have selected is JSON/XML – Simply decode the message as follows:

string deserializedMessage = Encoding.UTF8.GetString(eventArgs.Body)

If you are using the Binary format, you will need to perform deserialization using Protocol Buffers.

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.


Market/Bet Message Handling

In order to decrease the size of the messages sent and improve message transferring speed, all messages are sent in delta formats – meaning only changes will be sent to you.

Every message will hold a reference to the Fixture, Market, and Bet (see Markets section) that they belong to.

Example

The following is a snapshot message for 1X2 market:

<Message>
  <Header>
    <Type>3</Type>
    <MsgId>1</MsgId>
    <MsgGuid>6fbee8ea-bb90-45fb-bb53-1abe720bf618</MsgGuid>
    <ServerTimestamp>1491131330</ServerTimestamp>
  </Header>
  <Body>
    <Events>
      <Event FixtureId="3115994">
        <Markets>
          <Market Id="1" Name="1X2">
            <Provider Id="8" Name="Bet365" LastUpdate="1491131330137">
              <Bet Id="11287986013115994" Name="X" Status="1" Price="4.2" LastUpdate="1491097568314" />
              <Bet Id="11287986593115994" Name="2" Status="1" Price="4.5" LastUpdate="1491097568314" />
              <Bet Id="11287986563115994" Name="1" Status="1" Price="1.571" LastUpdate="1491097568314" />
            </Provider>
          </Market>
        </Markets>
      </Event>
    </Events>
  </Body>

Generic

The message is linked to Fixture Id 3115994 as seen in the example above.

A delta message will be sent as follows:

<Message>
  <Header>
    <Type>3</Type>
    <MsgId>5</MsgId>
    <MsgGuid>b6b66be0-e006-4f97-b66d-c10da8b00c99</MsgGuid>
    <ServerTimestamp>1491132216</ServerTimestamp>
  </Header>
  <Body>
    <Events>
      <Event FixtureId="3115994">
         <Markets>
          <Market Id="1" Name="1X2">
            <Provider Id="8" Name="Bet365" LastUpdate="1491132216336">
              <Bet Id="11287986563115994" Name="1" Status="1" Price="1.615" LastUpdate="1491098848826" />
            </Provider>
          </Market>
        </Markets>
      </Event>
    </Events>
  </Body>
</Message>

This message contains the Id of the Fixture as a reference, as did the previous message, but the only bet in it is the updated one. In this example, the price of the bet “1” bet was updated.

Last updated