59 行
1.8 KiB

  1. using Confluent.Kafka;
  2. using Confluent.Kafka.Admin;
  3. using JT808.DotNetty.Abstractions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Text;
  8. using Xunit;
  9. namespace JT808.DotNetty.Kafka.Test
  10. {
  11. public class JT808MsgProducerTest
  12. {
  13. public const string BootstrapServers = "172.16.19.120:9092";
  14. //public const string BootstrapServers = "192.168.3.11:9092";
  15. public JT808ProducerConfig JT808ProducerConfig = new JT808ProducerConfig
  16. {
  17. TopicName = "jt808test",
  18. BootstrapServers = BootstrapServers
  19. };
  20. public JT808MsgProducerTest()
  21. {
  22. using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = BootstrapServers }).Build())
  23. {
  24. try
  25. {
  26. adminClient.DeleteTopicsAsync(new List<string>() { JT808ProducerConfig.TopicName }).Wait();
  27. }
  28. catch (CreateTopicsException e)
  29. {
  30. Debug.WriteLine($"An error occured creating topic {e.Results[0].Topic}: {e.Results[0].Error.Reason}");
  31. }
  32. }
  33. }
  34. [Fact]
  35. public void Test1()
  36. {
  37. using (IJT808MsgProducer jT808MsgProducer = new JT808MsgProducer(JT808ProducerConfig))
  38. {
  39. jT808MsgProducer.ProduceAsync("123456", new byte[] { 0x7E, 0, 0x7E }).Wait();
  40. }
  41. }
  42. [Fact]
  43. public void Test2()
  44. {
  45. using (IJT808MsgProducer jT808MsgProducer = new JT808MsgProducer(JT808ProducerConfig))
  46. {
  47. jT808MsgProducer.ProduceAsync("123457", new byte[] { 0x7E, 0, 0x7E }).Wait();
  48. jT808MsgProducer.ProduceAsync("123456", new byte[] { 0x7E, 0, 0x7E }).Wait();
  49. }
  50. }
  51. }
  52. }