Stomp.Net
Stomp.Net copied to clipboard
Allow to use custom transport with default connection factory and extend default transport factory
Current code composition not allow easily use custom transport without copying lot of code from current classes. Using two small changes in PR is posible to register custom transport like this:
public class StompCustomTransportFactory : StompTransportFactory
{
private readonly StompConnectionSettings _stompConnectionSettings;
public StompCustomTransportFactory(StompConnectionSettings stompConnectionSettings) : base(stompConnectionSettings)
{
_stompConnectionSettings = stompConnectionSettings;
}
protected override ITransportFactory CreateTransportFactory(Uri location)
{
return location.Scheme.ToLower() switch
{
"ws" => new WebsocketTransportFactory(_stompConnectionSettings), // <-custom transport
_ => base.CreateTransportFactory(location),
};
}
}
internal static class Program
{
[STAThread]
private static void Main()
var url = "ws://example.com/ws";
var settings = new StompConnectionSettings()
{
// ...
};
var factory = new StompConnectionFactory(url, settings, new StompCustomTransportFactory(settings));
// ...
}
}