public bool Publish(BusChannel channel, Packet packet) { try { if (BindQueue(channel)) { var body = packet.GetByteArray(); var router = $"{GetChannelName(_exchangeName, channel)}.{packet.Service}"; _channel.BasicPublish(_exchangeName, router, false, _properties, body); } return(true); } catch (Exception ex) { return(false); } }
public bool Subscribe(BusChannel channel, PacketProcessor processor) { if (BindQueue(channel)) { string channelName = GetChannelName(_exchangeName, channel); //queue _queues.TryAdd(channelName, new ConcurrentQueue <Packet>()); var queue = _queues[channelName]; //processor List <PacketProcessor> subscriber = null; if (_subscribers.ContainsKey(channelName)) { subscriber = _subscribers[channelName]; } else { subscriber = new List <PacketProcessor>(); } AddProcessor2Subscriber(processor, subscriber); _subscribers.TryAdd(channelName, subscriber); //consumer var consumer = new EventingBasicConsumer(_channel); consumer.Received += (sender, args) => { var packet = args.Body.FromByteArray(); queue.Enqueue(packet); }; _channel.BasicConsume(channelName, true, consumer); return(true); } else { return(false); } }
private async Task <bool> _processor(BusChannel channel, Packet packet) { return(await Task.FromResult(true)); }
public DataRecordBuilder Channel(BusChannel channel) { record.Channel = channel; return(this); }