private async void RetrieveZookeeperBrokerTopics() { if (string.IsNullOrEmpty(ZookeeperHostServer)) { CurrentStatus = $"Zookeeper hosts is empty!"; MessageBox.Show("Please specify at least one zookeeper server!"); settings_valid = false; return; } if (!ValidateZookeeperSettings()) { CurrentStatus = $"Zookeeper hosts specified is not valid!"; settings_valid = false; MessageBox.Show("Zookeeper hosts specified is invalid! \r\n Please see format indicated in wartermark text!", "Zookeeper host is invalid"); return; } if (TopicItems.Any()) { TopicItems.Clear(); } using (IZookeeperClient client = new ZookeeperClient(new ZookeeperClientOptions(ZookeeperHostServer) { BasePath = "/", //default value ConnectionTimeout = TimeSpan.FromSeconds(10), //default value SessionTimeout = TimeSpan.FromSeconds(20), //default value OperatingTimeout = TimeSpan.FromSeconds(60), //default value ReadOnly = false, //default value SessionId = 0, //default value SessionPasswd = null, //default value EnableEphemeralNodeRestore = true //default value })) { CurrentStatus = $"Retrieving data from Zookeeper server {ZookeeperHostServer}."; try { var childNodes = await client.GetChildrenAsync("/brokers/topics"); if (childNodes.Any()) { Dispatcher.CurrentDispatcher.Invoke(() => { TopicItems.AddRange(childNodes); CanSelectTopic = true; CurrentStatus = $"Zookeeper topics has been fetched successfully."; }); } } catch (Exception ex) { settings_valid = false; TopicItems.Clear(); CurrentStatus = $"Error occurs when communicating with Zookeeper '{ZookeeperHostServer}'. {ex.Message}"; } finally { client.Dispose(); } } }
private void StartConsumeMessages() { var canStart = !string.IsNullOrEmpty(ZookeeperHostServer) && !string.IsNullOrEmpty(KafkaHostServer) && TopicItems.Any() && !string.IsNullOrEmpty(SelectedTopic); if (!canStart) { MessageBox.Show("Can't start consumer, please check zookeeper host, kafka host and selected topic!"); return; } ReceivedMessages.Clear(); Tables.Clear(); _cancelConsume = new CancellationTokenSource(); CurrentStatus = $"Consuming messages from topic:{SelectedTopic} ..."; DEKafkaMessageViewer.Common.KafkaConsumer consumer = new Common.KafkaConsumer(); var groupId = Guid.NewGuid().ToString(); consumer.ConsumeAsync(KafkaHostServer, SelectedTopic, groupId, _cancelConsume, (resultMsg) => { var msgBody = resultMsg.Message; EnableStop = true; OnMessageConsumed(msgBody); }); }