Beispiel #1
0
 public ReceiveState(BusReceiverState data, MethodInfo methodInfo,
     IServiceBusSerializer serializer, BrokeredMessage message)
 {
     Guard.ArgumentNotNull(data, "data");
     Guard.ArgumentNotNull(methodInfo, "methodInfo");
     Guard.ArgumentNotNull(serializer, "serializer");
     Guard.ArgumentNotNull(message, "message");
     this.Data = data;
     this.MethodInfo = methodInfo;
     this.Serializer = serializer;
     this.Message = message;
 }
Beispiel #2
0
 public ReceiverHelper(IBusConfiguration config, RetryPolicy retryPolicy, BusReceiverState data)
 {
     this.config = config;
     this.retryPolicy = retryPolicy;
     this.data = data;
 }
Beispiel #3
0
        /// <summary>
        /// Create a new Subscription.
        /// </summary>
        /// <param name="value">The data used to create the subscription</param>
        public void CreateSubscription(ServiceBusEnpointData value)
        {
            Guard.ArgumentNotNull(value, "value");

            //TODO determine how we can change the filters for an existing registered item
            //ServiceBusNamespaceClient

            lock (lockObject)
            {
                SubscriptionDescription desc = null;

                bool createNew = false;

                try
                {
                    // First, let's see if a item with the specified name already exists.
                    verifyRetryPolicy.ExecuteAction(() =>
                    {
                        desc = configurationFactory.NamespaceManager.GetSubscription(topic.Path, value.SubscriptionName);
                    });

                    createNew = (desc == null);
                }
                catch (MessagingEntityNotFoundException)
                {
                    // Looks like the item does not exist. We should create a new one.
                    createNew = true;
                }

                // If a item with the specified name doesn't exist, it will be auto-created.
                if (createNew)
                {
                    var descriptionToCreate = new SubscriptionDescription(topic.Path, value.SubscriptionName);

                    if (value.AttributeData != null)
                    {
                        var attr = value.AttributeData;
                        if (attr.DefaultMessageTimeToLiveSet())
                        {
                            descriptionToCreate.DefaultMessageTimeToLive = new TimeSpan(0, 0, attr.DefaultMessageTimeToLive);
                        }
                        descriptionToCreate.EnableBatchedOperations = attr.EnableBatchedOperations;
                        descriptionToCreate.EnableDeadLetteringOnMessageExpiration = attr.EnableDeadLetteringOnMessageExpiration;
                        if (attr.LockDurationSet())
                        {
                            descriptionToCreate.LockDuration = new TimeSpan(0, 0, attr.LockDuration);
                        }
                    }

                    try
                    {
                        var filter = new SqlFilter(string.Format(TYPE_HEADER_NAME + " = '{0}'", value.MessageType.FullName.Replace('.', '_')));
                        retryPolicy.ExecuteAction(() =>
                        {
                            desc = configurationFactory.NamespaceManager.CreateSubscription(descriptionToCreate, filter);
                        });
                    }
                    catch (MessagingEntityAlreadyExistsException)
                    {
                        // A item under the same name was already created by someone else, perhaps by another instance. Let's just use it.
                        retryPolicy.ExecuteAction(() =>
                        {
                            desc = configurationFactory.NamespaceManager.GetSubscription(topic.Path, value.SubscriptionName);
                        });
                    }
                }

                SubscriptionClient subscriptionClient = null;
                var rm = ReceiveMode.PeekLock;

                if (value.AttributeData != null)
                {
                    rm = value.AttributeData.ReceiveMode;
                }

                retryPolicy.ExecuteAction(() =>
                {
                    subscriptionClient = configurationFactory.MessageFactory.CreateSubscriptionClient(topic.Path, value.SubscriptionName, rm);
                });

                if (value.AttributeData != null && value.AttributeData.PrefetchCountSet())
                {
                    subscriptionClient.PrefetchCount = value.AttributeData.PrefetchCount;
                }

                BusReceiverState state = new BusReceiverState();
                state.Client = subscriptionClient;
                state.EndPointData = value;

                var helper = new ReceiverHelper(configuration, retryPolicy, state);
                mappings.Add(helper);
                helper.ProcessMessagesForSubscription();

            } //lock end
        }