public void SendMessage <T>(string exchange, string routeKey, T message, SendMessageOption option = null) { option ??= new SendMessageOption() { }; using var _channel = this._connection.CreateModel(); var bs = this._serializer.Serialize(message); var props = this.CreateBasicProperties(_channel, option); using var confirm = new ConfirmOrNot(_channel, option.Confirm, option.ConfirmTimeout); try { _channel.BasicPublish(exchange: exchange, routingKey: routeKey, basicProperties: props, body: bs); } catch { confirm.DontConfirmAnyMore(); throw; } }
void SendMessage <T>(string queue, T message, SendMessageOption option = null) { option ??= new SendMessageOption() { }; using var _channel = this._connection.CreateModel(); var bs = this._serializer.SerializeToBytes(message); var props = this.CreateBasicProperties(_channel, option); using var confirm = new ConfirmOrNot(_channel, option.Confirm, option.ConfirmTimeout); try { //这里queue为什么也是routing key _channel.BasicPublish(exchange: string.Empty, routingKey: queue, basicProperties: props, body: bs); } catch { confirm.DontConfirmAnyMore(); throw; } }