FIFA Connect Service Bus

.NET SDK, v3.0

1. Setup

SDK libraries to reference:

2. FIFA Connect Service Bus Client

2.1 Creating a client

The entry point of the SDK is FifaConnectServiceBusClient. With a single instance of this class all the requests can be made. In order to authenticate to the service you have to provide a set of client credentials.

2.1.1 Setup private certificate

In order to create a new instance of the client, there is a need of providing an implementation of IPrivateKeyStorage. By default SDK comes with class PrivateKeyMemoryStorage that implements mentioned interface. Next step is to provide instance(s) of X509Certificate2 into such container. Each certificate contains of the key (from generated file) and password (optionally). Please take a look at the following example:


var environment = ConnectServiceBusEnvironment.Beta;
var credentials = new ClientCredentials("clientId", "secretKey");

// TODO: fill keys

var certificate = new X509Certificate2();
certificate.Import(TestResources.cert_pfx, "Testing123", X509KeyStorageFlags.DefaultKeySet);
var privateStore = new PrivateKeyMemoryStorage(certificate);
2.1.2 Basic instance
var environment = ConnectServiceBusEnvironment.Beta;
var credentials = new ClientCredentials("clientId", "secretKey");
var client = new FifaConnectServiceBusClient(environment, credentials, privateStore);

where environment is an instance of type ConnectServiceBusEnvironment. It provides information about the service to make request to.

2.1.3 Logging

By default, the above constructor uses a NullLogger, which does nothing. However, to use logging, provide your own implementation of ILogger.

var environment = ConnectServiceBusEnvironment.Beta;
var credentials = new ClientCredentials("clientId", "secretKey");
var logger = new YourOwnLogger();
var client = new FifaConnectServiceBusClient(environment, credentials, privateStore, logger);;
2.1.4 Certificate client instance

In case of need for upload or download certificate, you have to use an instance of FifaConnectServiceBusCertificateClient.

var environment = ConnectServiceBusEnvironment.Beta;
var credentials = new ClientCredentials("clientId", "secretKey");

var certificateClient = new FifaConnectServiceBusCertificateClient(environment, credentials);

2.1.5 Disable encryption

Encryption can be disabled using setUseEncryption() method from FifaConnectServiceBusClient instance.

var environment = ConnectServiceBusEnvironment.Beta;
var credentials = new ClientCredentials("clientId", "secretKey");

var client = new FifaConnectServiceBusClient(environment, credentials, new NullPrivateKeyProvider());
client.UseEncryption = false;
2.1.6 Addressing a message

Recipient of the message is specified by the recipient parameter. It's actually a name of a queue that acts as an inbox for other client (e.g. registration system in a different MA).

2.2 Sending a message

In order to send a message in FIFA Connect Service Bus service, provide content as byte[]. A recipient needs to be provided as well.

By convention value of the recipient is the FIFA ID of the receiving organisation. However, for certain applications it may have format of FIFAID_application. In case of any doubts, please contact FIFA Connect Service Bus Support team to get proper value of recipient.

Example:

try
{
    await client.Send(recipient, content);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (PublicCertificateNotFoundException ex)
{
    // there is no public certificate for given queue
}
catch (CryptographyException ex)
{
    // exception when encrypting content
}
catch (QueueNotFoundException ex)
{
    // there is no queue for specified recipient
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

To send additional meta data of the message use overloaded send method:

var action = "/person/getDetails";
var properties = new Dictionary<string, string>();
properties.Add("id", "BVGE8T6");

await client.Send(recipient, content, action, properties);

2.3 Receive a message

Please note that the method is not transactional. Message is immediately removed from the queue. For transactional message processing use PeekLock method.

The timeout parameter can be specified. In Connect Service Bus context timeout defines how long a request waits before returning that there is no message in the queue. When no message is found, FifaConnectServiceBusClient will return null.

try
{
    var message = await client.Receive().ConfigureAwait(false);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (CryptographyException ex)
{
    // exception when encrypting content
}
catch (QueueNotFoundException ex)
{
    // there is no queue for specified recipient
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.4 Transactional receive

In order to receive a message from Connect Service Bus and leave it in the queue use PeekLock method. Received message will not be visible for other Connect Service Bus clients for 120 seconds. During that time period actions like Delete, Unlock or RenewLock can be triggered. If none of the above actions is taken, message will be returned to the queue.

In the Message some metadata can be found in property BrokerProperties. The most important are MessageId and LockToken that are used as required parameters in methods Delete, Unlock or RenewLock. In addition above properites can be found in instance of Message class.

try
{
    var message = client.PeekLock();
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (CryptographyException ex)
{
    // exception when encrypting content
}
catch (QueueNotFoundException ex)
{
    // there is no queue for specified recipient
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.5 Delete a message

Method used to delete a locked message.

try
{
    await client.Delete(message.Id, message.LockToken);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.6 Unlock a message

Message can be returned to the queue using Unlock method.

try
{
    await client.Unlock(message.Id, message.LockToken);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.7 Renew lock

Lock can be renewed for the next 120 seconds.

try
{
    await client.RenewLock(message.Id, message.LockToken);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.8 Upload a public certificate

Recommended way to upload a public certificate is the upload using console application located in certificate-upload-console folder. For more information please refer to Certificate Generation documentation. If console application can't be used, use UploadCertificate method instead. Take a look at the following example:

var certificateData = File.ReadAllBytes(certificateFilePath); // certificateFilePath: path to public_cert.pem file
try
{
    await client.UploadCertificate(certificateData);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

2.9 Download a public certificate

To download public certificate for specific organisation use DownloadCertificate method. Please take a look at the following example:

try
{
    var certificateRawData = await client.DownloadCertificate(queueIdentifier).ConfigureAwait(false);
}
catch (InvalidClientDataException ex)
{
    // data sent to the service was invalid
    var details = ex.BadRequestResponse;
}
catch (AuthenticationException ex)
{
    // invalid client credentials
}
catch (UnauthorizedException ex)
{
    // unauthorized
}
catch (DataNotFoundException ex)
{
    // certificate has not been found
}
catch (FifaConnectServiceBusException ex)
{
    // some other error occurred, see the details
    var response = ex.HttpOperationResponse;
}

3. Limits

3.1 Maximum queue size

Currently each recipient's queue has a quota of 80 GB (both content and message headers size is counted). When queue reaches its limit new messages cannot be send to the recipient, so senders get an error from Service Bus API and SDK.

3.2. Maximum time-to-live

Each queue stores messages for 7 days. If message is not received by the recipient messages then it is moved to dead-letter queue and support team receives notification about unprocessed message. On client request support team can move message to primary queue so that it can be received and processed by an application. Alternatively message can be permanently deleted from dead-letter queue.

3.3. Maximum delivery retries

If client using Connect Service Bus SDK downloads message but fails to process it correctly (i.e. handler throws an exception), then the counter of failed delivery is increased. If delivery fails 10 times, then message is moved to dead-letter queue. Depending on the reason different actions can be taken: * message is invalid or content is malformed, so that message cannot be processed by receiver - support team can delete the message, if needed sender should be notified that the message was invalid and was not processed by recipient. * issue on the receiving side preventing correct message to be processed - support team can move message to primary queue so that message can be reprocessed after the issue is solved on receiving side.

3.4 Thread-safety

Any instance members are not guaranteed to be thread safe. In particular all methods on FifaConnectServiceBusClient cannot be called from multiple threads simultaneously. If needed, new instance of FifaConnectServiceBusClient should be created per thread.

4. Release notes

The following changes were introduced in version 3.0 of the SDK when comparing to version 2.1: