C
C#15mo ago
PontiacGTX

❔ trying to consume signalr through gateway

I am using the followin json in my gateway
{
"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" ]
}
and the front end has this code
2 Replies
PontiacGTX
PontiacGTXOP15mo ago
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);
});
}
an it is returning that it cannot stablish connection
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.
my Gateway has
await app.UseOcelot(configuration);
app.UseWebSockets();
await app.UseOcelot(configuration);
app.UseWebSockets();
on program.cs my api has
app.MapControllers();
app.MapHub<DriversHub>("/DriversHub");
app.MapControllers();
app.MapHub<DriversHub>("/DriversHub");
my hub is defined like
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);
}

}
}
what am I doing wrong? there is no identity or claims as of now
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server