예제 #1
0
        public static async Task PublishTopics(Input input)
        {
            var functionInvoked = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var client          = ServerlessHelper.GetDbContext();
            var taskList        = new List <Task>();

            foreach (var topic in input.Topics)
            {
                var response = client.QueryAsync <TopicTable>(topic);
                var items    = await response.GetRemainingAsync();

                var databaseAccessed = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");

                foreach (var item in items)
                {
                    var payload = new
                    {
                        topic,
                        message          = input.Message,
                        fromPublisher    = input.FromPublisher,
                        functionInvoked  = functionInvoked,
                        databaseAccessed = databaseAccessed,
                        queueUrl         = item.QueueUrl
                    };
                    taskList.Add(SqsClient.SendMessageAsync(item.QueueUrl, Newtonsoft.Json.JsonConvert.SerializeObject(payload)));
                }
            }
            LambdaContext.Logger.Log("sent,");
            await Task.WhenAll(taskList);

            LambdaContext.Logger.Log("done,");
        }
예제 #2
0
        public static async Task <bool> PublishContents(Input input)
        {
            var client = ServerlessHelper.GetDbContext();

            foreach (var content in input.Contents)
            {
                var response = client.QueryAsync <ContentTable>(content.Key);
                var items    = await response.GetRemainingAsync();

                var message = new
                {
                    content,
                    message = input.Message
                };
                var sqsClient = ServerlessHelper.GetAmazonSqsClient();
                foreach (var item in items)
                {
                    if (item.Key.Equals(content.Key, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (CheckConditions(item.Condition, content.Value, item.Value))
                        {
                            await sqsClient.SendMessageAsync(item.QueueUrl, JsonConvert.SerializeObject(message));
                        }
                    }
                }
            }
            return(true);
        }
예제 #3
0
        private static async Task SubscribeContent(Input contentsInput)
        {
            var client = ServerlessHelper.GetDbContext();

            foreach (var content in contentsInput.Contents)
            {
                await client.SaveAsync(new ContentTable { QueueUrl = contentsInput.SubscriberId, Key = content.Key, Value = content.Value, Condition = content.Condition });
            }
        }
예제 #4
0
        private static async Task SubscribeTopics(Input input)
        {
            var client = ServerlessHelper.GetDbContext();

            foreach (var topic in input.Topics)
            {
                await client.SaveAsync(new TopicTable { QueueUrl = input.SubscriberId, TopicName = topic });
            }
        }
예제 #5
0
        public static async Task PublishTopics(Input input)
        {
            var functionInvoked = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var client          = ServerlessHelper.GetDbContext();

            foreach (var topic in input.Topics)
            {
                var response         = client.QueryAsync <TopicTable>(topic);
                var databaseAccessed = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");
                var items            = await response.GetRemainingAsync();

                var sqsClient = ServerlessHelper.GetAmazonSqsClient();

                foreach (var item in items)
                {
                    var payload = new
                    {
                        topic,
                        message          = input.Message,
                        fromPublisher    = input.FromPublisher,
                        functionInvoked  = functionInvoked,
                        databaseAccessed = databaseAccessed,
                        queueUrl         = item.QueueUrl
                    };

                    //var content = JsonConvert.SerializeObject(payload);
                    //var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(1) };
                    //var resp = httpClient.PostAsync("https://0achmjvzf2.execute-api.eu-central-1.amazonaws.com/pubsub/publishmessage", new StringContent(content, System.Text.Encoding.UTF8, "application/json"));
                    //LambdaContext.Logger.LogLine(resp.IsSuccessStatusCode.ToString());
                    //var err = await resp.Content.ReadAsStringAsync();
                    //LambdaContext.Logger.LogLine(err);

                    //var credentials = new BasicAWSCredentials(Serverless.Common.Environment.AccessKey, Serverless.Common.Environment.SecretKey);
                    //var client1 = new AmazonLambdaClient(credentials, RegionEndpoint.EUCentral1);
                    //var request = new InvokeRequest() { FunctionName = "PublishMessage", Payload = JsonConvert.SerializeObject(payload) };
                    //await client1.InvokeAsync(request);
                    //LambdaContext.Logger.LogLine(resp.StatusCode.ToString());
                    //LambdaContext.Logger.LogLine(resp.FunctionError.ToString());
                    //await ServerlessHelper.SendMessage(Newtonsoft.Json.JsonConvert.SerializeObject(payload));
                    await sqsClient.SendMessageAsync(item.QueueUrl, Newtonsoft.Json.JsonConvert.SerializeObject(payload));
                }
            }
        }
예제 #6
0
        public static async Task<bool> PublishFunctions(Input input)
        {
            var client = ServerlessHelper.GetDbContext();

            var response = client.QueryAsync<FunctionsTable>(input.SubscriptionTopic);
            var items = await response.GetRemainingAsync();
            var sqsClient = ServerlessHelper.GetAmazonSqsClient();
            var httpClient = new HttpClient();

            foreach (var item in items)
            {
                if (item.FunctionType == "url")
                {
                    var resp = await httpClient.GetAsync(item.MatchingFunction);
                    var responseString = await resp.Content.ReadAsStringAsync();
                    await sqsClient.SendMessageAsync(item.QueueUrl, JsonConvert.SerializeObject(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(responseString)));
                }
            }
            return true;
        }
예제 #7
0
        public static async Task <bool> PublishContents(Input input)
        {
            var functionInvoked = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var client          = ServerlessHelper.GetDbContext();

            var taskList = new List <Task>();

            foreach (var content in input.Contents)
            {
                var response = client.QueryAsync <ContentTable>(content.Key);
                var items    = await response.GetRemainingAsync();

                var databaseAccessed = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff");

                foreach (var item in items)
                {
                    var payload = new
                    {
                        content,
                        message          = input.Message,
                        fromPublisher    = input.FromPublisher,
                        functionInvoked  = functionInvoked,
                        databaseAccessed = databaseAccessed,
                        queueUrl         = item.QueueUrl
                    };
                    if (item.Key.Equals(content.Key, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (CheckConditions(item.Condition, content.Value, item.Value))
                        {
                            LambdaContext.Logger.LogLine($"Matched,");
                            taskList.Add(SqsClient.SendMessageAsync(item.QueueUrl, Newtonsoft.Json.JsonConvert.SerializeObject(payload)));
                        }
                    }
                }
            }
            LambdaContext.Logger.Log("sent,");
            await Task.WhenAll(taskList);

            LambdaContext.Logger.Log("done,");
            return(true);
        }
예제 #8
0
 private static async Task SubscribeFunctions(Input input)
 {
     var client = ServerlessHelper.GetDbContext();
     await client.SaveAsync(new FunctionsTable { QueueUrl = input.SubscriberId, SubscriptionType = input.SubscriptionType, MatchingInputs = input.MatchingInputs, MatchingFunction = input.MatchingFunction });
 }