public async Task persist_and_load_subscriptions()
        {
            var subscriptions = new Subscription[]
            {
                new Subscription(typeof(GreenMessage), theDestination)
                {
                    Accept = new string[] { "application/json" },
                },
                new Subscription(typeof(BlueMessage), theDestination),
                new Subscription(typeof(RedMessage), theDestination),
                new Subscription(typeof(OrangeMessage), theDestination),
            };

            var capabilities = new ServiceCapabilities
            {
                Subscriptions = subscriptions,
                Published     = new PublishedMessage[0]
            };

            subscriptions.Each(x => x.ServiceName = "ConsulSampleApp");

            await theRepository.PersistCapabilities(capabilities);

            var publishes = await theRepository.GetSubscribersFor(typeof(GreenMessage));

            publishes.Count().ShouldBe(1);

            publishes.Single().Accept.ShouldHaveTheSameElementsAs("application/json");

            publishes.Any(x => x.MessageType == typeof(GreenMessage).ToMessageAlias()).ShouldBeTrue();
        }
Exemplo n.º 2
0
 public async Task PersistCapabilities(ServiceCapabilities capabilities)
 {
     using (var session = _documentStore.LightweightSession())
     {
         session.Store(capabilities);
         await session.SaveChangesAsync();
     }
 }
        protected override void Initialize(ServiceCapabilities capabilities)
        {
            base.Initialize(capabilities);
            this._sessionFactory = new SessionFactory();
            IDataModel bfDataModel = new BrilliantFactoryDataModel();

            ModelContainer.LoadDataModel(bfDataModel);
        }
Exemplo n.º 4
0
 public IGrammar ForService()
 {
     return(Embed <ServiceCapabilityFixture>("If a service has capabilities:")
            .After(c =>
     {
         _current = Context.State.Retrieve <ServiceCapabilities>();
         _services.Add(_current);
     }));
 }
Exemplo n.º 5
0
        public override void TearDown()
        {
            _registry.Settings.Alter <MessagingSettings>(_ =>
            {
                _.DisableAllTransports    = true;
                _.ThrowOnValidationErrors = false;
            });

            ServiceCapabilities capabilities = null;

            using (var runtime = JasperRuntime.For(_registry))
            {
                capabilities = runtime.Capabilities;
            }

            Context.State.Store(capabilities);
        }
        public async Task can_write_then_read()
        {
            ServiceCapabilities services;

            var runtime = await JasperRuntime.ForAsync(_ =>
            {
                _.Handlers.DisableConventionalDiscovery(true);

                _.ServiceName = "AppWithSubscriptions";


                _.Subscribe.To <Message1>();
                _.Subscribe.To <Message2>();

                _.Publish.Message <Message3>();
                _.Publish.Message <Message4>();
                _.Publish.Message <Message5>();

                _.Settings.Alter <MessagingSettings>(x => x.ThrowOnValidationErrors = false);
            });

            try
            {
                services = runtime.Capabilities;

                services.Errors.Length.ShouldBeGreaterThan(0);
                services.Subscriptions.Length.ShouldBeGreaterThan(0);
                services.Published.Length.ShouldBeGreaterThan(0);
            }
            finally
            {
                await runtime.Shutdown();
            }

            services.WriteToFile("services.json");

            var services2 = ServiceCapabilities.ReadFromFile("services.json");

            services2.ShouldNotBeNull();
            services2.ServiceName.ShouldBe(services.ServiceName);

            services2.Subscriptions.Length.ShouldBe(2);
            services2.Published.Length.ShouldBe(services.Published.Length);
            services2.Errors.Length.ShouldBe(services.Errors.Length);
        }
Exemplo n.º 7
0
        public Task PersistCapabilities(ServiceCapabilities capabilities)
        {
            var ops = capabilities.Subscriptions
                      .Select(s => new KVTxnOp(s.ConsulId(), KVTxnVerb.Set)
            {
                Value = serialize(s)
            })
                      .ToList();

            var persist = new KVTxnOp(capabilities.ConsulId(), KVTxnVerb.Set)
            {
                Value = serialize(capabilities)
            };

            ops.Add(persist);

            return(client.KV.Txn(ops));
        }
        public static async Task<ServiceCapabilityCache> LoadAsync(ServiceCapabilities capability)
        {
            CapabilityDiscoveryResult capabilityDiscoveryResult = null;

            DiscoveryServiceCache cache = await LoadAsync();

            cache.DiscoveryInfoForServices.TryGetValue(capability.ToString(), out capabilityDiscoveryResult);

            if (cache == null || capabilityDiscoveryResult == null)
            {
                return null;
            }

            return new ServiceCapabilityCache
            {
                UserId = cache.UserId,
                CapabilityResult = capabilityDiscoveryResult
            };
        }
Exemplo n.º 9
0
        public static async Task <ServiceCapabilityCache> LoadAsync(ServiceCapabilities capability)
        {
            CapabilityDiscoveryResult capabilityDiscoveryResult = null;

            DiscoveryServiceCache cache = await LoadAsync();

            cache.DiscoveryInfoForServices.TryGetValue(capability.ToString(), out capabilityDiscoveryResult);

            if (cache == null || capabilityDiscoveryResult == null)
            {
                return(null);
            }

            return(new ServiceCapabilityCache
            {
                UserId = cache.UserId,
                CapabilityResult = capabilityDiscoveryResult
            });
        }
        public async Task find_subscriptions_for_a_message_type()
        {
            var subscriptions = new Subscription[]
            {
                new Subscription(typeof(GreenMessage), "something://localhost:3333/here".ToUri())
                {
                },
                new Subscription(typeof(GreenMessage), "something://localhost:4444/here".ToUri())
                {
                },
                new Subscription(typeof(GreenMessage), "something://localhost:5555/here".ToUri())
                {
                },
                new Subscription(typeof(BlueMessage), theDestination)
                {
                },
                new Subscription(typeof(RedMessage), theDestination)
                {
                },
                new Subscription(typeof(OrangeMessage), theDestination)
                {
                },
            };

            subscriptions.Each(x => x.ServiceName = "ConsulSampleApp");

            var capabilities = new ServiceCapabilities
            {
                Subscriptions = subscriptions,
                Published     = new PublishedMessage[0]
            };

            await theRepository.PersistCapabilities(capabilities);

            var greens = await theRepository.GetSubscribersFor(typeof(GreenMessage));

            greens.Length.ShouldBe(3);
        }
Exemplo n.º 11
0
 public static string ConsulId(this ServiceCapabilities capabilities)
 {
     return($"{ConsulSubscriptionRepository.CAPABILITY_PREFEX}{capabilities.ServiceName}");
 }
Exemplo n.º 12
0
        private void validate(JasperRuntime runtime, SubscriptionsInput input)
        {
            var files = new FileSystem();
            var dict  = new Dictionary <string, ServiceCapabilities>();

            files.FindFiles(input.DirectoryFlag, FileSet.Shallow("*.capabilities.json"))
            .Each(file =>
            {
                try
                {
                    Console.WriteLine("Reading " + file);

                    var capabilities = ServiceCapabilities.ReadFromFile(file);
                    if (dict.ContainsKey(capabilities.ServiceName))
                    {
                        ConsoleWriter.Write(ConsoleColor.Yellow,
                                            $"Duplicate service name '{capabilities.ServiceName}' from file {file}");
                    }
                    else
                    {
                        dict.Add(capabilities.ServiceName, capabilities);
                    }
                }
                catch (Exception e)
                {
                    ConsoleWriter.Write(ConsoleColor.Yellow, "Failed to read capabilities from file " + file);
                    Console.WriteLine(e);
                }
            });

            if (dict.ContainsKey(runtime.ServiceName))
            {
                dict[runtime.ServiceName] = runtime.Capabilities;
            }
            else
            {
                dict.Add(runtime.ServiceName, runtime.Capabilities);
            }

            var messaging = new MessagingGraph(dict.Values.ToArray());

            Console.WriteLine(messaging.ToJson());

            if (input.FileFlag.IsNotEmpty())
            {
                Console.WriteLine("Writing the messaging graph to " + input.FileFlag);
                messaging.WriteToFile(input.FileFlag);
            }

            if (messaging.HasAnyErrors())
            {
                ConsoleWriter.Write(ConsoleColor.Yellow, "Messaging errors detected!");

                if (!input.IgnoreFailuresFlag)
                {
                    throw new Exception("Validation failures detected.");
                }
            }
            else
            {
                ConsoleWriter.Write(ConsoleColor.Green, "All messages have matching, valid publishers and subscribers");
            }
        }
Exemplo n.º 13
0
 public Task PersistCapabilities(ServiceCapabilities capabilities)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 14
0
        public static async Task <CapabilityDiscoveryResult> GetCapabilityDiscoveryResultAsync(ServiceCapabilities serviceCapability)
        {
            var discoveryServiceInfo = await GetAllCapabilityDiscoveryResultAsync();

            DiscoveryServiceCache discoveryCache = null;

            var cacheResult = await DiscoveryServiceCache.LoadAsync(serviceCapability);

            if (cacheResult == null)
            {
                discoveryCache = await CreateAndSaveDiscoveryServiceCacheAsync();

                CapabilityDiscoveryResult capabilityDiscoveryResult = null;

                discoveryCache.DiscoveryInfoForServices.TryGetValue(serviceCapability.ToString(), out capabilityDiscoveryResult);

                return(capabilityDiscoveryResult);
            }
            else
            {
                return(cacheResult.CapabilityResult);
            }
        }
Exemplo n.º 15
0
 Task ISubscriptionsRepository.PersistCapabilities(ServiceCapabilities capabilities)
 {
     return(Task.CompletedTask);
 }
        public static async Task<CapabilityDiscoveryResult> GetCapabilityDiscoveryResultAsync(ServiceCapabilities serviceCapability)
        {
            var discoveryServiceInfo = await GetAllCapabilityDiscoveryResultAsync();

            DiscoveryServiceCache discoveryCache = null;

            var cacheResult = await DiscoveryServiceCache.LoadAsync(serviceCapability);

            if (cacheResult == null)
            {
                discoveryCache = await CreateAndSaveDiscoveryServiceCacheAsync();

                CapabilityDiscoveryResult capabilityDiscoveryResult = null;

                discoveryCache.DiscoveryInfoForServices.TryGetValue(serviceCapability.ToString(), out capabilityDiscoveryResult);

                return capabilityDiscoveryResult;
            }
            else
            {
                return cacheResult.CapabilityResult;
            }
        }