❔ trying to consume signalr through gateway
I am using the followin json in my gateway and the front end has this code
{
"DownstreamPathTemplate": "/ws",
"UpstreamPathTemplate": "/",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7200
}
]
},
{
"DownstreamPathTemplate": "/DriversHub/GetDriversDetail/{number}",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7200
}
],
"UpstreamPathTemplate": "/upwg/DriversHub/GetDriversDetail/{number}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ]
}
{
"DownstreamPathTemplate": "/ws",
"UpstreamPathTemplate": "/",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7200
}
]
},
{
"DownstreamPathTemplate": "/DriversHub/GetDriversDetail/{number}",
"DownstreamScheme": "ws",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7200
}
],
"UpstreamPathTemplate": "/upwg/DriversHub/GetDriversDetail/{number}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ]
}
2 Replies
hub: HubConnection | null = null;
constructor() {
this.onGetDriverCallBack = null;
this.hub = new signalR.HubConnectionBuilder().withUrl('http://localhost:7145/upgw/DriversHub').build();
this.hub.start();
console.log(this.hub);
this.hub.onreconnecting((error?: Error) => {
if (error) {
console.log(`Connection lost due to error: ${error.message.toString()}`);
}
});
this.hub.onreconnected(() => {
console.log('Connection reestablished');
});
this.hub.start().then(() => {
console.log('Connection established');
}).catch((error: Error) => {
console.log('Error establishing connection: ' + error.message);
});
}
hub: HubConnection | null = null;
constructor() {
this.onGetDriverCallBack = null;
this.hub = new signalR.HubConnectionBuilder().withUrl('http://localhost:7145/upgw/DriversHub').build();
this.hub.start();
console.log(this.hub);
this.hub.onreconnecting((error?: Error) => {
if (error) {
console.log(`Connection lost due to error: ${error.message.toString()}`);
}
});
this.hub.onreconnected(() => {
console.log('Connection reestablished');
});
this.hub.start().then(() => {
console.log('Connection established');
}).catch((error: Error) => {
console.log('Error establishing connection: ' + error.message);
});
}
Error establishing connection: Cannot start a HubConnection that is not in the 'Disconnected' state.
Error establishing connection: Cannot start a HubConnection that is not in the 'Disconnected' state.
await app.UseOcelot(configuration);
app.UseWebSockets();
await app.UseOcelot(configuration);
app.UseWebSockets();
app.MapControllers();
app.MapHub<DriversHub>("/DriversHub");
app.MapControllers();
app.MapHub<DriversHub>("/DriversHub");
public class DriversHub:Hub
{
private IDriversServices _driversServices;
private ILogger<DriversHub> _logger;
public DriversHub(IDriversServices driversServices, ILogger<DriversHub> logger)
{
_driversServices = driversServices;
_logger = logger;
}
public override async Task OnConnectedAsync()
{
var userName = Context.User?.Claims.FirstOrDefault(x => x.Type == "email")?.Value;
if (!string.IsNullOrEmpty(userName))
await Groups.AddToGroupAsync(Context.ConnectionId, userName);
await base.OnConnectedAsync();
}
public async Task GetDriversDetail(string number)
{
var model = new Data.Model.GetDriverInformationModel { Number = number};
try
{
DriverInfo info = new DriverInfo();
info = (await _driversServices.GetDriverInformation(model)).ToList();
await Clients.Users(number).SendAsync("OnGetDriverDetails"/*, dest*/, Factory.OkResponse(info));
}
catch (Exception ex)
{
_logger.LogException(ex, model);
}
}
}
public class DriversHub:Hub
{
private IDriversServices _driversServices;
private ILogger<DriversHub> _logger;
public DriversHub(IDriversServices driversServices, ILogger<DriversHub> logger)
{
_driversServices = driversServices;
_logger = logger;
}
public override async Task OnConnectedAsync()
{
var userName = Context.User?.Claims.FirstOrDefault(x => x.Type == "email")?.Value;
if (!string.IsNullOrEmpty(userName))
await Groups.AddToGroupAsync(Context.ConnectionId, userName);
await base.OnConnectedAsync();
}
public async Task GetDriversDetail(string number)
{
var model = new Data.Model.GetDriverInformationModel { Number = number};
try
{
DriverInfo info = new DriverInfo();
info = (await _driversServices.GetDriverInformation(model)).ToList();
await Clients.Users(number).SendAsync("OnGetDriverDetails"/*, dest*/, Factory.OkResponse(info));
}
catch (Exception ex)
{
_logger.LogException(ex, model);
}
}
}
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.