protected override void OnStartup(StartupEventArgs e) { try { base.OnStartup(e); var factory = new ConnectionFactory() { HostName = "localhost" }; Connection = factory.CreateConnection(); Channel = Connection.CreateModel(); var messageBusClient = new MessageBusPublisherClient(Channel, ExchangeName); MainWindow = new MainWindow(); MainViewModel mainViewModel = new MainViewModel(messageBusClient); MainWindow.DataContext = mainViewModel; MainWindow.Show(); } catch (Exception ex) { MessageBox.Show($"An error occurred while starting up the application. {ex.Message}"); Shutdown(); } }
static void Main(string[] args) { string exchangeName = "queueLink"; ConnectionFactory factory = new ConnectionFactory() { HostName = "localhost", UserName = "******", Password = "******" }; using var connection = factory.CreateConnection(); using var channel = connection.CreateModel(); { MessageBusPublisherClient publisher = new MessageBusPublisherClient(channel, exchangeName); string exitCode = ""; while (exitCode != "-1") { string id = ""; Console.WriteLine("Enter download ID"); id = Console.ReadLine().ToLower(); var updateMessage = new UpdateInformation { DownloadEndPoint = @$ "http://*****:*****@$ "http://localhost:57308/updates/{id}/information", Id = id }; Message <UpdateInformation> message = new Message <UpdateInformation>(Guid.NewGuid(), updateMessage); publisher.PostAsync(message); Console.WriteLine($"Message Send :: {message.Body}\n\n"); } } }