import { Payload, Result } from './model/Payload';

export class EcPublisher {
  /**
   * 
   * @param payloadSchema 消息格式
   * @param sendType 01 - 群发：同一个topic如果多个目标环境订阅，这些目标环境都发
   *                 02 - 定向：只发送到客户端所处环境对应的目标环境
   */
  static publish(payloadSchema: Payload, sendType: String) {
    const Pulsar = require('pulsar-client');
    (async () => {
      const client = new Pulsar.Client({
        //todo 定时拉取注册中心作缓存
        serviceUrl: 'pulsar://101.37.145.159:6650',
      });

      const producer = await client.createProducer({
        topic: 'persistent://yongqiangTenant/yongqiangNamespace/yongqiangTopic',
      });

      // Send messages
      const msg = JSON.stringify(payloadSchema);
      producer.send({
        data: Buffer.from(msg),
      });
    })();
  }
}


