Skip to main content

ProconTEL 4 App

This section describes the PctBridge module. This module is able to communicate with ProconTEL 3, which has Bridge Endpoint running. Module can be used in any application hosted in the ProconTEL 4 environment that uses the components pipeline builder.

Module Installation​

To install the PctBridge module into a project, the Nuget Package Manager Console can be used:

Install-Package ProconTel.Components.Communication.PctBridge -ProjectName <ProjectName>

The NuGet package can be found in the repository: https://nexus.macrix.eu/repository/pct2022/

Usage in the code​

Overview​

To use the PctBridge module, it is necessary to register the module in the services using the AddProconTel3Bridge() extension and also initialize the bridge's Rest Server in the app using UseProconTel3Bridge(). It can be done by using the Standard API only (the Minimal API can't be used).

builder.Services.AddProconTel3Bridge<TInputConsumer>(configuration);
app.UseProconTel3Bridge();

Configuration​

Inline​

Inline configuration contains a delegate of the PctBridgeConfiguration class. All the parameters that can be set are listed below.

ParameterTypeDescription
Pct3BridgeUrlStringProconTEL 3 Bridge Url
AuthorityUrlStringProconTEL Authority Url
AuthUsernameStringProconTEL Authority username
AuthPasswordStringProconTEL Authority password
builder.Services.AddProconTel3Bridge<TInputConsumer>(cfg =>
{
cfg.Pct3BridgeUrl = "http://procontel3url:9000";
cfg.AuthorityUrl = "https://procontel-auth:9800";
cfg.AuthUsername = "user";
cfg.AuthPassword = "password";
});

Using appsettings.json​

It is possible to configure the ProconTEL 3 Bridge module using the appsettings.json file in the "ProconTel3Bridge" section.

{
"ProconTel3Bridge": {
"Pct3BridgeUrl": "http://procontel3url:9000",
"AuthorityUrl": "https://procontel-auth:9800",
"AuthUsername": "user",
"AuthPassword": "password"
}
}
builder.Services.AddProconTel3Bridge<TInputConsumer>(builder.Configuration);

BridgeMessage definition​

BridgeMessage is used as a container for incoming and outgoing Bridge data.

using System.Text.Json.Nodes;

namespace ProconTel.Components.Communication.Rest;

public class BridgeMessage
{
public string? RoutingId { get; init; }
public JsonObject? JsonMessage { get; init; }
}
  • RoutingId contains the message routing ID, which may be used for filtering and mapping.
  • JsonMessage is the message payload.

BridgeMessage handlers​

Handling message incoming from ProconTEL 3​

Incoming messages may be handled in a class that implements ProconTel.Pipelines.IConsumer<ProconTel.Components.Communication.Rest.BridgeMessage> interface.

Example​
using ProconTel.Components.Communication.Rest;
using ProconTel.Pipelines;
using ProconTel.SDK.Messaging;

public class BridgeMessageHandler : IConsumer<BridgeMessage>
{
private readonly IMessageBus _messageBus;

public BridgeMessageHandler(IMessageBus messageBus)
{
_messageBus = messageBus;
}

public async Task ConsumeAsync(BridgeMessage data)
{
await _messageBus.PublishAsync(data.RoutingId ?? string.Empty, data.JsonMessage);
}
}

Sending messages to ProconTEL 3​

Outgoing messages may be sent using IBridgeMessageSender.SendMessageAsync() method. IBridgeMessageSender can be resolved using dependency injection.

using System.Text.Json.Nodes;
using ProconTel.Components.Communication.PctBridge;
using ProconTel.Components.Communication.Rest;

public class BridgeSender
{
private readonly IBridgeMessageSender _bridgeMessageSender;

public BridgeSender(IBridgeMessageSender bridgeMessageSender)
{
_bridgeMessageSender = bridgeMessageSender;
}

public async Task SendMessageAsync()
{
await _bridgeMessageSender.SendMessageAsync(new BridgeMessage
{
RoutingId = "myRoutingId",
JsonMessage = JsonNode.Parse("{\"Key\": \"Value\"}")?.AsObject()
});
}
}

There is also an overload of the SendMessageAsync() method available, which accepts routingId and jsonMessage directly:

await _bridgeMessageSender.SendMessageAsync("myRoutingId", JsonNode.Parse("{\"Key\": \"Value\"}")?.AsObject());

Example implementation​

using ProconTel.Components.Communications.PctBridge;

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureProcontel(builder.Configuration);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddProconTel(builder.Configuration);

builder.Services.AddMessageHandler<AppMessageHandler, object>().WithRoutingId("*");
builder.Services.AddProconTel3Bridge<BridgeMessageHandler>(cfg =>
{
cfg.Pct3BridgeUrl = "http://procontel3url:9000";
cfg.AuthorityUrl = "https://procontel-auth:9800";
cfg.AuthUsername = "user";
cfg.AuthPassword = "password";
});

var app = builder.Build();
app.UseProconTel();
app.MapProconTel();
app.UseProconTel3Bridge();

await app.RunAsync();
  • AppMessageHandler uses IBridgeMessageSender.SendMessageAsync() to send data to ProconTEL 3.
  • BridgeMessageHandler implements IConsumer<BridgeMessage> to handle data incoming from ProconTEL 3.