public Peer(PeerConfiguration configuration, IServiceBus bus, IPublisher publisher, ISubscriber subscriber, IConnectionTracker connectionTracker) { _bus = bus; _subscriber = subscriber; _publisher = publisher; _connectionTracker = connectionTracker; Identity = new PeerIdentity(configuration.Context, configuration.Metadata); _connectionTracker.PeerConnected += HandlePeerConnected; _connectionTracker.PeerDisconnected += HandlePeerDisconnected; _subscriber.MessageReceived += msg => HandleReceivedMessage(msg.Sender, msg.Content); }
public void ShouldDiscoverWithMetadata() { var bus = new YottoBusFactory().Create(); var conf = new PeerConfiguration(string.Empty, new Dictionary <string, string>() { ["key"] = "value" }); using (var peer1 = bus.CreatePeer(conf)) { peer1.Connect(); AwaitAssert(TimeSpan.FromSeconds(5), () => { Assert.True(peer1.GetConnectedPeers().Any()); Assert.True(peer1.GetConnectedPeers().First().Metadata.Has("key")); Assert.AreEqual(peer1.GetConnectedPeers().First().Metadata.Get("key"), "value"); }); } }
public PeerAutoConnectService(IPeerService peerService, IConfiguration configuration, ILoggerFactory loggerFactory) { _peerService = peerService; _logger = loggerFactory.CreateLogger <PeerService>(); _configuration = configuration.GetConfiguration <PeerConfiguration>(); }
/// <summary> /// Creates the peer on the bus. /// </summary> /// <param name="configuration">The peer configuration.</param> /// <returns> /// Created peer /// </returns> public IPeer CreatePeer(PeerConfiguration configuration) { var conf = new Ninject.Parameters.ConstructorArgument("configuration", configuration); return(_container.Get <IPeer>(conf)); }