Exemple #1
0
        public async Task <string> Publish(string message)
        {
            await Limiter.Add(1);

            await using (var context = new AzureMessagingContext(QueueUrl))
            {
                var msg = new azureMessaging.ServiceBusMessage(message);

                await context.Sender.SendMessageAsync(msg);

                return(msg.MessageId);
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates a new message from the specified payload.
 /// </summary>
 /// <param name="body">The payload of the message in bytes</param>
 internal ServiceBusReceivedMessage(ReadOnlyMemory <byte> body)
 {
     SentMessage = new ServiceBusMessage(body);
 }
        public static async Task SendServiceBusMessageAsync(ServiceBusSender queueSender, Azure.Messaging.ServiceBus.ServiceBusMessage message, ILogger log, TimeSpan delay)
        {
            if (queueSender == null)
            {
                throw new ArgumentNullException(nameof(queueSender));
            }

            log.LogInformation($"Sending message with delay of {delay.TotalMinutes} minutes.");
            await queueSender.ScheduleMessageAsync(message, DateTimeOffset.Now.Add(delay)).ConfigureAwait(false);
        }
        public static async Task SendServiceBusMessageAsync(ServiceBusSender queueSender, string messageContent, ILogger log, TimeSpan delay)
        {
            var message = new Azure.Messaging.ServiceBus.ServiceBusMessage(messageContent);

            await SendServiceBusMessageAsync(queueSender, message, log, delay).ConfigureAwait(false);
        }
 /// <summary>
 ///   Attempts to add a message to the batch, ensuring that the size
 ///   of the batch does not exceed its maximum.
 /// </summary>
 ///
 /// <param name="message">Message to attempt to add to the batch.</param>
 ///
 /// <returns><c>true</c> if the message was added; otherwise, <c>false</c>.</returns>
 ///
 public bool TryAdd(ServiceBusMessage message)
 {
     return(InnerBatch.TryAdd(message));
 }
        public static ServiceBusReceivedMessage ServiceBusReceivedMessage(
            BinaryData body         = default,
            string messageId        = default,
            string partitionKey     = default,
            string viaPartitionKey  = default,
            string sessionId        = default,
            string replyToSessionId = default,
            TimeSpan timeToLive     = default,
            string correlationId    = default,
            string label            = default,
            string to          = default,
            string contentType = default,
            string replyTo     = default,
            DateTimeOffset scheduledEnqueueTime     = default,
            IDictionary <string, object> properties = default,
            Guid lockTokenGuid          = default,
            int deliveryCount           = default,
            DateTimeOffset lockedUntil  = default,
            long sequenceNumber         = -1,
            string deadLetterSource     = default,
            long enqueuedSequenceNumber = default,
            DateTimeOffset enqueuedTime = default)
        {
            var sentMessage = new ServiceBusMessage
            {
                Body                 = body,
                CorrelationId        = correlationId,
                Label                = label,
                To                   = to,
                ContentType          = contentType,
                ReplyTo              = replyTo,
                ScheduledEnqueueTime = scheduledEnqueueTime
            };

            if (messageId != default)
            {
                sentMessage.MessageId = messageId;
            }
            if (partitionKey != default)
            {
                sentMessage.PartitionKey = partitionKey;
            }
            if (viaPartitionKey != default)
            {
                sentMessage.ViaPartitionKey = viaPartitionKey;
            }
            if (sessionId != default)
            {
                sentMessage.SessionId = sessionId;
            }
            if (replyToSessionId != default)
            {
                sentMessage.ReplyToSessionId = replyToSessionId;
            }
            if (timeToLive != default)
            {
                sentMessage.TimeToLive = timeToLive;
            }
            if (properties != default)
            {
                sentMessage.Properties = properties;
            }

            return(new ServiceBusReceivedMessage
            {
                SentMessage = sentMessage,
                LockTokenGuid = lockTokenGuid,
                DeliveryCount = deliveryCount,
                LockedUntil = lockedUntil,
                SequenceNumber = sequenceNumber,
                DeadLetterSource = deadLetterSource,
                EnqueuedSequenceNumber = enqueuedSequenceNumber,
                EnqueuedTime = enqueuedTime
            });
        }
Exemple #7
0
 /// <summary>
 ///   Called when a 'process message' event is triggered.
 /// </summary>
 ///
 /// <param name="message">The set of arguments to identify the context of the event to be processed.</param>
 /// <param name="session"></param>
 ///
 private Task OnProcessMessageAsync(ServiceBusMessage message, ServiceBusSession session) => _processMessage(message, session);
Exemple #8
0
 /// <summary>
 /// Renews the lock on the message specified by the lock token. The lock will be renewed based on the setting specified on the queue.
 /// </summary>
 /// <remarks>
 /// When a message is received in <see cref="ReceiveMode.PeekLock"/> mode, the message is locked on the server for this
 /// receiver instance for a duration as specified during the Queue/Subscription creation (LockDuration).
 /// If processing of the message requires longer than this duration, the lock needs to be renewed.
 /// For each renewal, it resets the time the message is locked by the LockDuration set on the Entity.
 /// </remarks>
 public virtual async Task RenewLockAsync(
     ServiceBusMessage message,
     CancellationToken cancellationToken = default)
 {
     message.SystemProperties.LockedUntilUtc = await _receiver.RenewLockAsync(message.SystemProperties.LockToken).ConfigureAwait(false);
 }