Beispiel #1
0
        private bool Match(string subscriberName, SubscriptionRule desc, Message message)
        {
            if (message == null || message.Header == null)
            {
                return(false);
            }

            RoutingRuleValidator v = RoutingRuleValidator.CreateRoutingRuleValidatorFromCache(desc);

            if (v == null)
            {
                _log.Write(LogType.Error, "[PushSenderAgent] Create routing rule validator failed for " + subscriberName);
                return(false);
            }

            if (v.Match(message))
            {
                _log.Write("[PushSenderAgent] Message (type " + message.Header.Type + ") matched the subscription rule of " + subscriberName + ", route the message.");
                return(true);
            }
            else
            {
                if (v.LastError != null)
                {
                    _log.Write(v.LastError);
                }
                _log.Write("[PushSenderAgent] Message (type " + message.Header.Type + ") does not matched the subscription rule of " + subscriberName + ", block the message.");
                return(false);
            }
        }
Beispiel #2
0
        private static void Test_SubscribeCriteria()
        {
            SubscriptionRule sc = new SubscriptionRule();

            sc.Type = RoutingRuleType.MessageType;

            string xml = sc.ToXMLString();

            MessageBox.Show(xml);

            SubscriptionRule sc1 = XObjectManager.CreateObject <SubscriptionRule>(xml);

            MessageBox.Show(sc1.ToXMLString());
        }
Beispiel #3
0
        private FunctionApp FunctionApp(string name, InputMap <string> appSettings, SubscriptionFilterConfig?subscriptionFilterConfig = null)
        {
            var storageAccount = new Pulumi.Azure.Storage.Account(name, new Pulumi.Azure.Storage.AccountArgs
            {
                ResourceGroupName      = _resourceGroup.Name,
                Location               = _resourceGroup.Location,
                AccountTier            = "Standard",
                AccountReplicationType = "LRS",
            });

            var plan = new Plan(name, new PlanArgs
            {
                Location          = _resourceGroup.Location,
                ResourceGroupName = _resourceGroup.Name,
                Kind = "FunctionApp",
                Sku  = new Pulumi.Azure.AppService.Inputs.PlanSkuArgs
                {
                    Tier = "Dynamic",
                    Size = "Y1",
                },
            });

            var serviceBusSubscription = new Subscription(name, new SubscriptionArgs()
            {
                Name              = name,
                NamespaceName     = _serviceBusNamespace.Name,
                TopicName         = _serviceBusTopic.Name,
                ResourceGroupName = _resourceGroup.Name,
                MaxDeliveryCount  = 10
            });

            if (subscriptionFilterConfig != null)
            {
                var typesList = new List <string>();
                typesList.AddRange(subscriptionFilterConfig.MessageTypes);
                if (subscriptionFilterConfig.AssemblyToScan != null)
                {
                    var handlerTypes = subscriptionFilterConfig.AssemblyToScan.GetTypes()
                                       .Where(t => t.GetInterfaces()
                                              .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRequestHandler <>))).ToList();

                    Console.Out.WriteLine("Got handler Types: " + string.Join(' ', handlerTypes.Select(t => t.Name)));

                    var messageTypes = handlerTypes.Select(ht =>
                                                           ht.GetInterfaces()
                                                           .FirstOrDefault(i => i.GetGenericTypeDefinition() == typeof(IRequestHandler <>))
                                                           .GenericTypeArguments.First()
                                                           )
                                       .ToList();
                    Console.Out.WriteLine("Got message Types: " + string.Join(' ', messageTypes.Select(t => t.Name)));

                    typesList.AddRange(messageTypes.Select(t => t.Name));
                }

                if (typesList.Any())
                {
                    var filterExpression = string.Join(" OR ", typesList.Select(t => $"sys.Label='{t}'"));
                    Console.Out.WriteLine("Creating Filter Expression: " + filterExpression);
                    var subFilter = new SubscriptionRule(name, new SubscriptionRuleArgs()
                    {
                        ResourceGroupName = _resourceGroup.Name,
                        NamespaceName     = _serviceBusNamespace.Name,
                        TopicName         = _serviceBusTopic.Name,
                        SubscriptionName  = name,
                        FilterType        = "SqlFilter",
                        SqlFilter         = filterExpression
                    });
                }
            }

            // create a new app settings input map - avoids adding the exception for having the same key but different value on the next function app
            var funcAppSettings = InputMap <string> .Merge(appSettings, new InputMap <string>()
            {
                { "ServiceBusSubscription", serviceBusSubscription.Name },
                { "WEBSITE_RUN_FROM_PACKAGE", "1" }
            });

            var functionApp = new FunctionApp($"magicbus-{name}", new FunctionAppArgs()
            {
                Name = $"magicbus-{name}",
                ResourceGroupName       = _resourceGroup.Name,
                HttpsOnly               = true,
                Version                 = "~3",
                AppServicePlanId        = plan.Id,
                StorageAccountName      = storageAccount.Name,
                StorageAccountAccessKey = storageAccount.PrimaryAccessKey,
                AppSettings             = funcAppSettings,
            });

            return(functionApp);
        }