Пример #1
0
        /// <summary>
        /// Fetch data from Canal Server, but have no auto Ack
        /// </summary>
        /// <param name="fetchSize">Fetch data Size. If you set the value to null or less than or equal to 0, the value will be reset to 1000. </param>
        /// <param name="timeout">Fetch data timeout. If you set the value to null or less than or equal to 0, the value will be reset to -1. -1 means no timeout.</param>
        /// <param name="timeOutUnit">Timeout unit. Default value is <see cref="FetchDataTimeoutUnitType.Millisecond"/>.</param>
        /// <returns></returns>
        public async Task <Message> GetWithoutAckAsync(int fetchSize, long?timeout, FetchDataTimeoutUnitType timeOutUnit = FetchDataTimeoutUnitType.Millisecond)
        {
            ValidateState(ConnectionState.Subscribed, nameof(GetWithoutAckAsync));

            var size = fetchSize <= 0 ? 1000 : fetchSize;
            var time = (timeout == null || timeout < 0) ? -1 : timeout;

            var get = new Get()
            {
                AutoAck     = false,
                Destination = _options.Destination,
                ClientId    = _options.ClientId,
                FetchSize   = size,
                Timeout     = (long)time,
                Unit        = (int)timeOutUnit
            };

            var pack = new Packet()
            {
                Type = PacketType.Get,
                Body = get.ToByteString()
            }.ToByteArray();

            await _client.WritePacketAsync(pack);

            var p = await _client.ReadPacketAsync();

            return(DeserializeMessage(p));
        }
Пример #2
0
        /// <summary>
        /// Fetch data from Canal Server, have auto Ack
        /// </summary>
        /// <param name="fetchSize">Fetch data Size. If you set the value to null or less than or equal to 0, the value will be reset to 1000. </param>
        /// <param name="timeout">Fetch data timeout. If you set the value to null or less than or equal to 0, the value will be reset to -1. -1 means no timeout.</param>
        /// <param name="timeOutUnit">Timeout unit. Default value is <see cref="FetchDataTimeoutUnitType.Millisecond"/>.</param>
        /// <returns></returns>
        public async Task <Message> GetAsync(int fetchSize, long?timeout,
                                             FetchDataTimeoutUnitType timeOutUnit = FetchDataTimeoutUnitType.Millisecond)
        {
            var message = await GetWithoutAckAsync(fetchSize, timeout, timeOutUnit);

            await AckAsync(message.Id);

            return(message);
        }
 /// <summary>
 /// Fetch data from Canal Server, but have no auto Ack
 /// </summary>
 /// <param name="fetchSize">Fetch data Size. If you set the value to null or less than or equal to 0, the value will be reset to 1000. </param>
 /// <param name="timeout">Fetch data timeout. If you set the value to null or less than or equal to 0, the value will be reset to -1. -1 means no timeout.</param>
 /// <param name="timeOutUnit">Timeout unit. Default value is <see cref="FetchDataTimeoutUnitType.Millisecond"/>.</param>
 /// <returns></returns>
 public Task <Message> GetWithoutAckAsync(int fetchSize, long?timeout,
                                          FetchDataTimeoutUnitType timeOutUnit = FetchDataTimeoutUnitType.Millisecond)
 {
     return(_currentConn.GetWithoutAckAsync(fetchSize, timeout));
 }