public static void Start() { try { Console.WriteLine("Starting Publisher...."); var connectionOption = new ConnectionOptions("127.0.0.1", 1883); //var connectionOption = new ConnectionOptions("127.0.0.1", 1884); var credential = new Credentials("PublisherFromPublisherCode", "", ""); var publisher = new Publisher(new ConsoleLogger()); publisher.Create(connectionOption, credential); publisher.OnConnected += eventArgs => { Console.WriteLine("Connected successfully with MQTT Brokers."); }; publisher.OnDisconnected += eventArgs => { Console.WriteLine("Disconnected from MQTT Brokers."); }; publisher.OnMessageReceived += eventArgs => { try { string topic = eventArgs.ApplicationMessage.Topic; if (string.IsNullOrWhiteSpace(topic) == false) { string payload = Encoding.UTF8.GetString(eventArgs.ApplicationMessage.Payload); Console.WriteLine($"Topic: {topic}. Message Received: {payload}"); } } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } }; publisher.Connect(); PublishMessage(publisher); //To keep the app running in container //https://stackoverflow.com/questions/38549006/docker-container-exits-immediately-even-with-console-readline-in-a-net-core-c Task.Run(() => Thread.Sleep(Timeout.Infinite)).Wait(); publisher.Disconnect(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task Update_Publisher() { var publisher = await PublisherHelpers.CreateValidPublisher(); publisher.Name.Should().Be("SubPop"); var sut = Publisher.Create(publisher.Id, "NewPop", @"\\pics\scott.jpg", "..."); await PublisherHelpers.UpdatePublisher(sut); await _fixture.Context.Entry(publisher).ReloadAsync(); publisher.Name.Should().Be("NewPop"); }
private Publisher CreatePublisher() => Publisher.Create(new PublisherId(SequentialGuid.NewSequentialGuid()), "Name", "Less");