public BrokerConnection(string uri, string realm) { _channel = new WampChannelFactory() .ConnectToRealm(realm) .WebSocketTransport(uri) .JsonSerialization() .Build(); Func <Task> connect = async() => { Log.InfoFormat("Trying to connect to broker {0}", uri); try { await _channel.Open(); Log.Debug("Connection Opened."); _subject.OnNext(Connected.Yes(new Broker(_channel))); } catch (Exception) { Log.Debug("Connection Failed."); _subject.OnNext(Connected.No <IBroker>()); throw; } }; _reconnector = new WampChannelReconnector(_channel, connect); }
public BrokerConnection(string uri, string realm) { var channel = new WampChannelFactory() .ConnectToRealm(realm) .WebSocketTransport(new Uri(uri)) .JsonSerialization() .Build(); async Task Connect() { Log.Information("Trying to connect to broker {brokerUri}", uri); try { await channel.Open(); Log.Debug("Connection Opened."); _subject.OnNext(Connected.Yes(new Broker(channel))); } catch (Exception exception) { Log.Error(exception, "Connection Failed."); _subject.OnNext(Connected.No <IBroker>()); throw; } } _reconnector = new WampChannelReconnector(channel, Connect); }
public void SetupRemoteConnection() { var factory = new DefaultWampChannelFactory(); _remoteChannel = factory.CreateJsonChannel(location, realm); Task connect() { return(Task.Run(async() => { try { _logger.Info(this, "Trying to connect"); _remoteChannel.Open().Wait(5000); IWampRealmProxy realm = _remoteChannel.RealmProxy; _logger.Info(this, "registering RPC"); await realm.Services.RegisterCallee(_service); } catch (Exception ex) { _logger.Error(this, ex.Message); var exe = ex; while (exe.InnerException != null) { exe = exe.InnerException; _logger.Error(this, exe.Message); } await Task.Delay(5000); throw; } })); } _reconnector = new WampChannelReconnector(_remoteChannel, connect); _reconnector.Start(); }