public TransactionalDeliveryHandler(IDeliveryHandler inner)
		{
			if (inner == null)
				throw new ArgumentNullException("inner");

			this.inner = inner;
		}
		public TransactionScopeDeliveryHandler(
			IDeliveryHandler inner, TransactionScopeOption scopeOption, TransactionOptions transactionOptions)
		{
			if (inner == null)
				throw new ArgumentNullException("inner");

			this.inner = inner;
			this.scopeOption = scopeOption;
			this.transactionOptions = transactionOptions;
		}
예제 #3
0
 public void ProduceAsync(string topic, ArraySegment <byte>?key, ArraySegment <byte>?val, IDeliveryHandler deliveryHandler, DateTime?timestamp = null, int?partition = null, bool blockIfQueueFull = true)
 => Produce(
     topic,
     val == null ? null : val.Value.Array,
     val == null ? 0 : val.Value.Offset,
     val == null ? 0 : val.Value.Count,
     key == null ? null : key.Value.Array,
     key == null ? 0 : key.Value.Offset,
     key == null ? 0 : key.Value.Count,
     timestamp?.Ticks,
     partition ?? RD_KAFKA_PARTITION_UA,
     blockIfQueueFull,
     deliveryHandler);
예제 #4
0
 public void ProduceAsync(string topic, byte[] key, byte[] val, IDeliveryHandler deliveryHandler, DateTime?timestamp = null, int?partition = null, bool blockIfQueueFull = true)
 => Produce(topic, val, 0, val?.Length ?? 0, key, 0, key?.Length ?? 0, timestamp?.Ticks, partition ?? RD_KAFKA_PARTITION_UA, blockIfQueueFull, deliveryHandler);
예제 #5
0
 public DeliveryController(IDeliveryProvider deliveryProvider, IDeliveryHandler deliveryHandler, IDeliveryValidator deliveryValidator)
 {
     this.deliveryProvider  = deliveryProvider;
     this.deliveryHandler   = deliveryHandler;
     this.deliveryValidator = deliveryValidator;
 }
예제 #6
0
 public TypedDeliveryHandlerShim(TKey key, TValue val, IDeliveryHandler <TKey, TValue> handler)
 {
     Key     = key;
     Value   = val;
     Handler = handler;
 }
예제 #7
0
 public void ProduceAsync(string topic, byte[] key, int keyOffset, int keyLength, byte[] val, int valOffset, int valLength, int partition, bool blockIfQueueFull, IDeliveryHandler deliveryHandler)
 => Produce(topic, val, valOffset, valLength, key, keyOffset, keyLength, null, partition, blockIfQueueFull, deliveryHandler);
예제 #8
0
        private void ProduceImpl(
            string topic,
            byte[] val, int valOffset, int valLength,
            byte[] key, int keyOffset, int keyLength,
            Timestamp timestamp,
            Partition partition,
            IEnumerable <IHeader> headers,
            IDeliveryHandler deliveryHandler)
        {
            if (timestamp.Type != TimestampType.CreateTime)
            {
                if (timestamp != Timestamp.Default)
                {
                    throw new ArgumentException("Timestamp must be either Timestamp.Default, or Timestamp.CreateTime.");
                }
            }

            ErrorCode err;

            if (this.enableDeliveryReports && deliveryHandler != null)
            {
                // Passes the TaskCompletionSource to the delivery report callback via the msg_opaque pointer

                // Note: There is a level of indirection between the GCHandle and
                // physical memory address. GCHandle.ToIntPtr doesn't get the
                // physical address, it gets an id that refers to the object via
                // a handle-table.
                var gch = GCHandle.Alloc(deliveryHandler);
                var ptr = GCHandle.ToIntPtr(gch);

                err = KafkaHandle.Produce(
                    topic,
                    val, valOffset, valLength,
                    key, keyOffset, keyLength,
                    partition.Value,
                    timestamp.UnixTimestampMs,
                    headers,
                    ptr);

                if (err != ErrorCode.NoError)
                {
                    // note: freed in the delivery handler callback otherwise.
                    gch.Free();
                }
            }
            else
            {
                err = KafkaHandle.Produce(
                    topic,
                    val, valOffset, valLength,
                    key, keyOffset, keyLength,
                    partition.Value,
                    timestamp.UnixTimestampMs,
                    headers,
                    IntPtr.Zero);
            }

            if (err != ErrorCode.NoError)
            {
                throw new KafkaException(KafkaHandle.CreatePossiblyFatalError(err, null));
            }
        }
예제 #9
0
 public TransactionScopeDeliveryHandler(IDeliveryHandler inner, TransactionScopeOption scopeOption)
     : this(inner, scopeOption, new TransactionOptions())
 {
 }
예제 #10
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, DateTime timestamp, int partition)
 => Produce(topic, key, val, deliveryHandler, timestamp, partition, true);
예제 #11
0
 public void ProduceAsync(string topic, byte[] key, int keyOffset, int keyLength, byte[] val, int valOffset, int valLength, DateTime timestamp, int partition, IDeliveryHandler deliveryHandler)
 => Produce(topic, val, valOffset, valLength, key, keyOffset, keyLength, timestamp, partition, true, deliveryHandler);
예제 #12
0
 public void ProduceAsync(string topic, byte[] key, int keyOffset, int keyLength, byte[] val, int valOffset, int valLength, DateTime timestamp, IDeliveryHandler deliveryHandler)
 => Produce(topic, val, valOffset, valLength, key, keyOffset, keyLength, timestamp, RD_KAFKA_PARTITION_UA, true, deliveryHandler);
		public TransactionScopeDeliveryHandler(IDeliveryHandler inner, TransactionScopeOption scopeOption)
			: this(inner, scopeOption, new TransactionOptions())
		{
		}
		public TransactionScopeDeliveryHandler(IDeliveryHandler inner)
			: this(inner, TransactionScopeOption.Required)
		{
		}
예제 #15
0
        public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, DateTime?timestamp = null, int?partition = null, bool blockIfQueueFull = true)
        {
            var handler = new TypedDeliveryHandlerShim(key, val, deliveryHandler);

            producer.ProduceAsync(topic, KeySerializer?.Serialize(key), ValueSerializer?.Serialize(val), handler, timestamp, partition, blockIfQueueFull);
        }
예제 #16
0
 public TransactionScopeDeliveryHandler(IDeliveryHandler inner)
     : this(inner, TransactionScopeOption.Required)
 {
 }
예제 #17
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, DateTime timestamp)
 => Produce(topic, key, val, deliveryHandler, timestamp, Producer.RD_KAFKA_PARTITION_UA, true);
예제 #18
0
 /// <summary>
 /// Produces a keyed message to a partition of the current Topic and notifies the caller of progress via a callback interface.
 /// </summary>
 /// <param name="payload">Payload to send to Kafka. Can be null.</param>
 /// <param name="deliveryHandler">IDeliveryHandler implementation used to notify the caller when the given produce request completes or an error occurs.</param>
 /// <param name="key">(Optional) The key associated with <paramref name="payload"/> (or null if no key is specified).</param>
 /// <param name="partition">(Optional) The topic partition to which <paramref name="payload"/> will be sent (or -1 if no partition is specified).</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="deliveryHandler"/> is null.</exception>
 /// <remarks>Methods of <paramref name="deliveryHandler"/> will be executed in an RdKafka-internal thread and will block other operations - consider this when implementing IDeliveryHandler.
 /// Use this overload for high-performance use cases as it does not use TPL and reduces the number of allocations.</remarks>
 public void Produce(byte[] payload, IDeliveryHandler deliveryHandler, byte[] key = null, Int32 partition = RD_KAFKA_PARTITION_UA, bool blockIfQueueFull = true)
 {
     Produce(payload, payload?.Length ?? 0, deliveryHandler, key, key?.Length ?? 0, partition, blockIfQueueFull);
 }
예제 #19
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler)
 => Produce(topic, key, val, deliveryHandler, null, Producer.RD_KAFKA_PARTITION_UA, true);
예제 #20
0
 public void ProduceAsync(string topic, byte[] key, byte[] val, IDeliveryHandler deliveryHandler)
 => Produce(topic, val, 0, val?.Length ?? 0, key, 0, key?.Length ?? 0, null, RD_KAFKA_PARTITION_UA, true, deliveryHandler);
예제 #21
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, int partition, bool blockIfQueueFull)
 => Produce(topic, key, val, deliveryHandler, null, partition, blockIfQueueFull);
예제 #22
0
 public void ProduceAsync(string topic, byte[] key, int keyOffset, int keyLength, byte[] val, int valOffset, int valLength, bool blockIfQueueFull, IDeliveryHandler deliveryHandler)
 => Produce(topic, val, valOffset, valLength, key, keyOffset, keyLength, null, RD_KAFKA_PARTITION_UA, blockIfQueueFull, deliveryHandler);
예제 #23
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, int partition)
 => Produce(topic, key, val, deliveryHandler, null, partition, true);
예제 #24
0
        private void Produce(string topic, TKey key, TValue val, DateTime?timestamp, int partition, bool blockIfQueueFull, IDeliveryHandler <TKey, TValue> deliveryHandler)
        {
            var handler  = new TypedDeliveryHandlerShim(key, val, deliveryHandler);
            var keyBytes = KeySerializer?.Serialize(key);
            var valBytes = ValueSerializer?.Serialize(val);

            producer.Produce(topic, valBytes, 0, valBytes == null ? 0 : valBytes.Length, keyBytes, 0, keyBytes == null ? 0 : keyBytes.Length, timestamp, partition, blockIfQueueFull, handler);
        }
예제 #25
0
 public void ProduceAsync(string topic, TKey key, TValue val, IDeliveryHandler <TKey, TValue> deliveryHandler, bool blockIfQueueFull)
 => Produce(topic, key, val, deliveryHandler, null, Producer.RD_KAFKA_PARTITION_UA, blockIfQueueFull);