예제 #1
0
        private static async void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            Console.WriteLine("Sending a message to queue BariMessagesQueue...\n");

            var message = new BariMessage();

            var sqsMessageRequest = new SendMessageRequest
            {
                QueueUrl    = myQueueUrl,
                MessageBody = message.Body
            };

            message.MessageId      = Guid.NewGuid().ToString();
            message.MicroServiceId = _microserviceId;
            message.RequisitionId  = Guid.NewGuid().ToString();

            foreach (var _property in message.GetType().GetProperties())
            {
                var attribute = new MessageAttributeValue();
                var value     = _property.GetValue(message, null) ?? "(null)";
                attribute.StringValue = value.ToString();
                attribute.DataType    = "String";
                sqsMessageRequest.MessageAttributes.Add(_property.Name, attribute);
            }
            await sqs.SendMessageAsync(sqsMessageRequest);

            Console.WriteLine("Message sended to BariMessagesQueue.\n");
        }
        private static Message GetMessage(Amazon.SQS.Model.Message sqsMessage)
        {
            MessageAttributeValue messageAttributeValue = sqsMessage.MessageAttributes["Type"];
            Type type = GetType(messageAttributeValue.StringValue);

            return((Message)JsonConvert.DeserializeObject(sqsMessage.Body, type));
        }
예제 #3
0
        public SqsDispatcher(IOptions <SQSDispatcherOptions <T> > options, ISerializer serializer, ILogger <SqsDispatcher <T> > logger)
            : base(logger)
        {
            _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
            var config = options?.Value ?? throw new ArgumentNullException(nameof(options));

            _queueUrl = config.QueueUrl ?? throw new Exception("No queue url set for type: " + (TypeCache <T> .FriendlyName ?? string.Empty));

            var sqsConfig = new AmazonSQSConfig
            {
                ServiceURL = config.ServiceURL
            };

            if (!string.IsNullOrEmpty(config.RegionEndpoint))
            {
                sqsConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(config.RegionEndpoint);
            }

            config.AwsDispatcherConfiguration?.Invoke(sqsConfig);

            _client = new AmazonSQSClient(sqsConfig);

            _contentType = new MessageAttributeValue
            {
                DataType    = AttributeType,
                StringValue = _serializer.ContentType
            };
        }
예제 #4
0
파일: Program.cs 프로젝트: bwhli/MetrICX
        static public void publishTransferMessage(ConfirmedTransaction trx)
        {
            eventCounter++;
            var msgStr = JsonConvert.SerializeObject(trx);
            Dictionary <String, MessageAttributeValue> messageAttributes = new Dictionary <string, MessageAttributeValue>();

            messageAttributes["from"] = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = trx.From
            };
            messageAttributes["to"] = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = trx.To
            };
            messageAttributes["value"] = new MessageAttributeValue
            {
                DataType    = "Number",
                StringValue = trx.GetIcxValue().ToString()
            };

            var request = new PublishRequest("arn:aws:sns:ap-southeast-2:850900483067:ICX_Transfer", msgStr, "transfer");

            request.MessageAttributes = messageAttributes;

            GetSNS().PublishAsync(request);

            Console.WriteLine($"Published message to AWS : ICX_Transfer, txHash " + trx.TxHash);
        }
예제 #5
0
        public SnsDispatcher(IOptions <SNSOptions <T> > options, ISerializer serializer, ILogger <SnsDispatcher <T> > logger)
            : base(logger)
        {
            _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
            var config = options?.Value ?? throw new ArgumentNullException(nameof(options));

            var snsConfig = new AmazonSimpleNotificationServiceConfig
            {
                ServiceURL = config.ServiceURL
            };

            if (!string.IsNullOrEmpty(config.RegionEndpoint))
            {
                snsConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(config.RegionEndpoint);
            }

            config.AwsDispatcherConfiguration?.Invoke(snsConfig);
            _client = new AmazonSimpleNotificationServiceClient(snsConfig);

            _contentType = new MessageAttributeValue
            {
                DataType    = AttributeType,
                StringValue = _serializer.ContentType
            };

            _valueTypeName = new MessageAttributeValue
            {
                DataType    = AttributeType,
                StringValue = typeof(T).AssemblyQualifiedName
            };
            _topicArn = config.TopicArn ?? throw new Exception("No topic arn set for type: " + (TypeCache <T> .FriendlyName ?? string.Empty));
        }
        public void SendSms(String message, String phoneNumber, String senderID, String SMSType = "Transactional")
        {
            MessageAttributeValue mMessageAttributeValue = new MessageAttributeValue();

            mMessageAttributeValue.DataType    = "String";
            mMessageAttributeValue.StringValue = senderID;

            MessageAttributeValue mMessageAttributeValue2 = new MessageAttributeValue();

            mMessageAttributeValue2.DataType    = "String";
            mMessageAttributeValue2.StringValue = SMSType;

            Dictionary <String, MessageAttributeValue> smsAttributes =
                new Dictionary <String, MessageAttributeValue>();

            smsAttributes.Add("DefaultSenderID", mMessageAttributeValue);
            smsAttributes.Add("DefaultSMSType", mMessageAttributeValue2);

            var mPublishRequest = new PublishRequest();

            mPublishRequest.Message           = message;
            mPublishRequest.PhoneNumber       = phoneNumber;
            mPublishRequest.MessageAttributes = smsAttributes;

            client.Publish(mPublishRequest);
        }
        public MessageAttributes GetMessageAttributes(string message)
        {
            var props = JObject.Parse(message).Value <JObject>("MessageAttributes")?.Properties();

            if (props == null)
            {
                return(new MessageAttributes());
            }

            var dict = new Dictionary <string, MessageAttributeValue>();

            foreach (var prop in props)
            {
                var propData = prop.Value;
                if (propData == null)
                {
                    continue;
                }

                var dataType  = propData["Type"].ToString();
                var dataValue = propData["Value"].ToString();

                var isString = dataType == "StringValue";

                var mav = new MessageAttributeValue
                {
                    DataType    = dataType,
                    StringValue = isString ? dataValue : null,
                    BinaryValue = !isString?Convert.FromBase64String(dataValue) : null
                };
                dict.Add(prop.Name, mav);
            }

            return(new MessageAttributes(dict));
        }
예제 #8
0
파일: Publisher.cs 프로젝트: santhign/Grid
        public async Task <string> PublishAsync(object message, Dictionary <string, string> attributes)
        {
            Dictionary <string, MessageAttributeValue> _messageattributes = new Dictionary <string, MessageAttributeValue>();

            foreach (string key in attributes.Keys)
            {
                MessageAttributeValue _attributeValue = new MessageAttributeValue();
                _attributeValue.DataType    = "String";
                _attributeValue.StringValue = attributes[key];
                _messageattributes.Add(key, _attributeValue);
            }
            if (!_initialised)
            {
                await Initialise();
            }
            PublishRequest request = new PublishRequest
            {
                TopicArn          = _topicArn,
                MessageAttributes = _messageattributes,
                Message           = JsonConvert.SerializeObject(message)
            };
            PublishResponse response = await _snsClient.PublishAsync(request);

            return(response.HttpStatusCode.ToString());
        }
예제 #9
0
        private async Task <SendMessageBatchRequestEntry> StoreMessageAsync(SendMessageBatchRequestEntry sendMessageRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_storageClient == null)
            {
                return(sendMessageRequest);
            }

            CheckMessageAttributes(sendMessageRequest.MessageAttributes);

            var messageContentStr  = sendMessageRequest.MessageBody;
            var messageContentSize = Encoding.UTF8.GetBytes(messageContentStr).Length;            // LongLength;

            var messageAttributeValue = new MessageAttributeValue
            {
                DataType    = "Number",
                StringValue = messageContentSize.ToString()
            };

            // !!!
            sendMessageRequest.MessageAttributes.Add(SQSConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);

            var storeReference = await _storageClient.PutDataAsync(sendMessageRequest.MessageBody, null, cancellationToken).ConfigureAwait(false);

            sendMessageRequest.MessageBody = JsonConvert.SerializeObject(storeReference);

            return(sendMessageRequest);
        }
 public void Add(String attributeName, String attributeValue)
 {
     Attributes[attributeName] = new MessageAttributeValue
     {
         DataType    = "String",
         StringValue = attributeValue
     };
 }
 public void Add(String attributeName, int attributeValue)
 {
     Attributes[attributeName] = new MessageAttributeValue
     {
         DataType    = "Number",
         StringValue = attributeValue.ToString()
     };
 }
예제 #12
0
 public static void Set(this IDictionary <string, MessageAttributeValue> attributes, string key, string value)
 {
     attributes[key] = new MessageAttributeValue
     {
         DataType    = "String",
         StringValue = value
     };
 }
예제 #13
0
        private void AppendMessageTypeAttribute(string messageType, Dictionary <string, MessageAttributeValue> messageAttributes)
        {
            var messageAttributeValue = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = messageType
            };

            messageAttributes.Add(SQSConstants.MESSAGE_TYPE_NAME, messageAttributeValue);
        }
        public void Add(String attributeName, List <Object> attributeValue)
        {
            String valueString = "[" + String.Join(", ", attributeValue.ToArray()) + "]";

            Attributes[attributeName] = new MessageAttributeValue
            {
                DataType    = "String.Array",
                StringValue = valueString
            };
        }
예제 #15
0
        private MessageAttributeValue CreateStringMessageAttr(string value)
        {
            var messageAttrValue = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = value
            };

            return(messageAttrValue);
        }
예제 #16
0
 public static void Set(this IDictionary <string, MessageAttributeValue> attributes, string key, Guid?value)
 {
     if (value.HasValue)
     {
         attributes[key] = new MessageAttributeValue
         {
             DataType    = "String",
             StringValue = value.ToString()
         };
     }
 }
예제 #17
0
 public static void Set(this IDictionary <string, MessageAttributeValue> attributes, string key, TimeSpan?value)
 {
     if (value.HasValue)
     {
         attributes[key] = new MessageAttributeValue
         {
             DataType    = "String",
             StringValue = value.Value.TotalMilliseconds.ToString("F0")
         };
     }
 }
예제 #18
0
    public PublishMetadata AddMessageAttribute(string key, MessageAttributeValue value)
    {
        if (MessageAttributes == null)
        {
            MessageAttributes = new Dictionary <string, MessageAttributeValue>(StringComparer.Ordinal);
        }

        MessageAttributes[key] = value;

        return(this);
    }
        protected async Task <PublishToSNSResult> PublishToEndpointAsync(string endpointArn, string message)
        {
            Amazon.SimpleNotificationService.Model.PublishRequest pReq = new Amazon.SimpleNotificationService.Model.PublishRequest();

            if ((model.TimeToLive ?? 0) > 0)
            {
                string ttlAttrKeyAPNS = "";
                switch (model.TargetEnvironment)
                {
                case TargetEnvironmentType.Sandbox:
                    ttlAttrKeyAPNS = "AWS.SNS.MOBILE.APNS_SANDBOX.TTL";
                    break;

                default:
                    ttlAttrKeyAPNS = "AWS.SNS.MOBILE.APNS.TTL";
                    break;
                }
                string ttlAttrKeyGCM = "AWS.SNS.MOBILE.GCM.TTL";

                Dictionary <String, MessageAttributeValue> messageAttributes = new Dictionary <String, MessageAttributeValue>();
                MessageAttributeValue value = new MessageAttributeValue();
                value.DataType    = "String";
                value.StringValue = model.TimeToLive.ToString();

                messageAttributes[ttlAttrKeyAPNS] = value;
                messageAttributes[ttlAttrKeyGCM]  = value;
                pReq.MessageAttributes            = messageAttributes;
            }

            pReq.TargetArn        = endpointArn;
            pReq.MessageStructure = "json";
            pReq.Message          = message;

            try
            {
                PublishResponse pRes = await snsClient.PublishAsync(pReq);

                return(new PublishToSNSSuccessfulResult(pRes.MessageId));
            }
            catch (EndpointDisabledException)
            {
                return(new PublishToSNSEndpointDisabledResult());
            }
            catch (InvalidParameterException exception)
            {
                if (exception.Message.Contains("No endpoint found for the target arn specified"))
                {
                    return(new PublishToSNSEndpointNotFoundResult());
                }
                throw exception;
            }
        }
예제 #20
0
        private async Task <Boolean> SendMessageAsync(String emailBody, CaseDetails caseDetails, String emailFrom, Boolean suppressResponse)
        {
            if (!suppressResponse)
            {
                try
                {
                    AmazonSQSClient amazonSQSClient = new AmazonSQSClient(sqsRegion);
                    try
                    {
                        SendMessageRequest sendMessageRequest = new SendMessageRequest();
                        sendMessageRequest.QueueUrl    = secrets.sqsEmailURL;
                        sendMessageRequest.MessageBody = emailBody;
                        Dictionary <string, MessageAttributeValue> MessageAttributes = new Dictionary <string, MessageAttributeValue>();
                        MessageAttributeValue messageTypeAttribute1 = new MessageAttributeValue();
                        messageTypeAttribute1.DataType    = "String";
                        messageTypeAttribute1.StringValue = caseDetails.customerName;
                        MessageAttributes.Add("Name", messageTypeAttribute1);
                        MessageAttributeValue messageTypeAttribute2 = new MessageAttributeValue();
                        messageTypeAttribute2.DataType    = "String";
                        messageTypeAttribute2.StringValue = caseDetails.customerEmail;
                        MessageAttributes.Add("To", messageTypeAttribute2);
                        MessageAttributeValue messageTypeAttribute3 = new MessageAttributeValue();
                        messageTypeAttribute3.DataType    = "String";
                        messageTypeAttribute3.StringValue = "Northampton Borough Council: Your Call Number is " + caseReference;;
                        MessageAttributes.Add("Subject", messageTypeAttribute3);
                        MessageAttributeValue messageTypeAttribute4 = new MessageAttributeValue();
                        messageTypeAttribute4.DataType    = "String";
                        messageTypeAttribute4.StringValue = emailFrom;
                        MessageAttributes.Add("From", messageTypeAttribute4);
                        sendMessageRequest.MessageAttributes = MessageAttributes;
                        SendMessageResponse sendMessageResponse = await amazonSQSClient.SendMessageAsync(sendMessageRequest);
                    }
                    catch (Exception error)
                    {
                        await SendFailureAsync("Error sending SQS message", error.Message);

                        Console.WriteLine("ERROR : SendMessageAsync : Error sending SQS message : '{0}'", error.Message);
                        Console.WriteLine("ERROR : SendMessageAsync : " + error.StackTrace);
                        return(false);
                    }
                }
                catch (Exception error)
                {
                    await SendFailureAsync("Error starting AmazonSQSClient", error.Message);

                    Console.WriteLine("ERROR : SendMessageAsync :  Error starting AmazonSQSClient : '{0}'", error.Message);
                    Console.WriteLine("ERROR : SendMessageAsync : " + error.StackTrace);
                    return(false);
                }
            }
            return(true);
        }
예제 #21
0
        public SqsBatchedDispatcher(IOptionsMonitor <SQSDispatcherOptions <T> > options, ISerializer serializer, ILogger <SqsDispatcher <T> > logger, ChannelWriter <SendSqsMessageCommand> messageWriter)
            : base(logger)
        {
            _options       = options ?? throw new ArgumentNullException(nameof(options));
            _serializer    = serializer ?? throw new ArgumentNullException(nameof(serializer));
            _messageWriter = messageWriter ?? throw new ArgumentNullException(nameof(messageWriter));

            _contentType = new MessageAttributeValue
            {
                DataType    = AttributeType,
                StringValue = _serializer.ContentType
            };
        }
예제 #22
0
파일: Program.cs 프로젝트: bwhli/MetrICX
        static public void publishContractMethodMessage(ConfirmedTransaction trx)
        {
            eventCounter++;
            var msgStr = JsonConvert.SerializeObject(trx);
            Dictionary <String, MessageAttributeValue> messageAttributes = new Dictionary <string, MessageAttributeValue>();

            messageAttributes["from"] = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = trx.From
            };
            messageAttributes["contract"] = new MessageAttributeValue
            {
                DataType    = "String",
                StringValue = trx.To
            };
            if (trx.Data != null && !(trx.Data is string) && trx.Data.method != null)
            {
                messageAttributes["method"] = new MessageAttributeValue
                {
                    DataType    = "String",
                    StringValue = trx.Data.method.Value
                };
            }

            List <string> eventList = new List <string>();

            foreach (var eventitem in trx.TxResultDetails.EventLogs)
            {
                string eventName = eventitem.Indexed[0];
                if (eventName.IndexOf("(") > 0)
                {
                    eventName = eventName.Substring(0, eventName.IndexOf("("));
                }
                eventList.Add(eventName);
            }

            messageAttributes["events"] = new MessageAttributeValue
            {
                DataType    = "String.Array",
                StringValue = "[\"" + string.Join("\",\"", eventList) + "\"]"
            };

            var request = new PublishRequest("arn:aws:sns:ap-southeast-2:850900483067:ICX_Contract_Method", msgStr, "score method");

            request.MessageAttributes = messageAttributes;

            GetSNS().PublishAsync(request);

            Console.WriteLine($"Published message to AWS : ICX_Contract_Method, txHash " + trx.TxHash);
        }
예제 #23
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                AmazonSimpleNotificationServiceClient snsClient;

                if (ddlCredentialsType.SelectedValue == "custom")
                {
                    RegionEndpoint regionEndpoint = RegionEndpoint.GetBySystemName(ddlRegion.SelectedValue);
                    snsClient = new AmazonSimpleNotificationServiceClient(txtAccessKey.Text.Trim(), txtSecretKey.Text.Trim(), regionEndpoint);
                }
                else
                {
                    //default, configure via web.config
                    snsClient = new AmazonSimpleNotificationServiceClient();
                }

                var smsAttributes = new Dictionary <string, MessageAttributeValue>();

                MessageAttributeValue senderID = new MessageAttributeValue();
                senderID.DataType    = "String";
                senderID.StringValue = "AwsSnsTest";

                MessageAttributeValue smsType = new MessageAttributeValue();
                smsType.DataType    = "String";
                smsType.StringValue = ddlMessageType.SelectedValue;

                MessageAttributeValue maxPrice = new MessageAttributeValue();
                maxPrice.DataType    = "Number";
                maxPrice.StringValue = ddlMaxPrice.SelectedValue;

                smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID);
                smsAttributes.Add("AWS.SNS.SMS.SMSType", smsType);
                smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice);

                var snsResponse = snsClient.Publish(new PublishRequest
                {
                    Message           = txtMessage.Text,
                    PhoneNumber       = txtTo.Text,
                    MessageAttributes = smsAttributes,
                });

                var serializer = new JavaScriptSerializer();
                lblResult.Text = serializer.Serialize(snsResponse);
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.ToString();
            }
        }
예제 #24
0
        public static void SendMessage(string my_access_key, string my_secret_key, string sender_ID, string Message, string ToPhoneNumber)
        {
            try
            {
                AmazonSimpleNotificationServiceClient smsClient =
                    new AmazonSimpleNotificationServiceClient(my_access_key, my_secret_key, Amazon.RegionEndpoint.USEast1);

                var smsAttributes = new Dictionary <string, MessageAttributeValue>();


                //MessageAttributeValue senderID =   A custom ID that contains up to 11 alphanumeric characters, including at least one letter and no spaces. The sender ID is displayed as the message sender on the receiving device. For example, you can use your business brand to make the message source easier to recognize.

                MessageAttributeValue senderID = new MessageAttributeValue();
                senderID.DataType    = "String";
                senderID.StringValue = sender_ID;

                MessageAttributeValue sMSType = new MessageAttributeValue();
                sMSType.DataType    = "String";
                sMSType.StringValue = "Transactional";

                MessageAttributeValue maxPrice = new MessageAttributeValue();
                maxPrice.DataType    = "Number";
                maxPrice.StringValue = "0.5";

                CancellationTokenSource source = new CancellationTokenSource();
                CancellationToken       token  = source.Token;


                smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID);
                smsAttributes.Add("AWS.SNS.SMS.SMSType", sMSType);
                smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice);

                PublishRequest publishRequest = new PublishRequest();
                publishRequest.Message           = Message;
                publishRequest.MessageAttributes = smsAttributes;
                publishRequest.PhoneNumber       = ToPhoneNumber;

                Task <PublishResponse> result = smsClient.PublishAsync(publishRequest, token);
                result.Wait();
                Console.WriteLine(result.Result.HttpStatusCode);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException == null ? ex.Message : ex.InnerException.Message);
                Console.ReadLine();
            }
        }
예제 #25
0
    public PublishMetadata AddMessageAttribute(string key, IReadOnlyCollection <byte> data)
    {
        if (data == null)
        {
            throw new ArgumentNullException(nameof(data));
        }

        var mav = new MessageAttributeValue();

        mav.BinaryValue = data;
        mav.DataType    = "Binary";

        MessageAttributes[key] = mav;

        return(this);
    }
        public void Set(string key, string value)
        {
            if (!_messageAttributes.ContainsKey(key))
            {
                var messageAttributeValue = new MessageAttributeValue()
                {
                    DataType    = "String",
                    StringValue = value
                };

                _messageAttributes.Add(key, messageAttributeValue);
            }
            else
            {
                Logger.Log(message: "New Relic key already exists in MessageAttributes collection.", rawLogging: false, level: "DEBUG");
            }
        }
예제 #27
0
        /// <summary>
        /// добавляет пользовательский атрибут с ссответствующим типом
        /// </summary>
        /// <param name="attributeName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public SendMessageRequest SetMessageAttribute(string attributeName, string value)
        {
            var attr = new MessageAttributeValue()
            {
                DataType = AttributeValueType.String, StringValue = value
            };

            if (MessageAttribute.ContainsKey(attributeName))
            {
                MessageAttribute[attributeName] = attr;
            }
            else
            {
                MessageAttribute.Add(attributeName, attr);
            }
            return(this);
        }
        /// <summary>Send sms using amazon SNS service</summary>
        /// <param name="phoneNumber"></param>
        /// <param name="otp"></param>
        public static string SendSMS(string phoneNumber, string otp)
        {
            try
            {
                AmazonSimpleNotificationServiceClient smsClient = new AmazonSimpleNotificationServiceClient
                                                                      (GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.APSoutheast1);

                var smsAttributes = new Dictionary <string, MessageAttributeValue>();

                MessageAttributeValue senderID = new MessageAttributeValue();
                senderID.DataType    = "String";
                senderID.StringValue = "ArthurClive";

                MessageAttributeValue sMSType = new MessageAttributeValue();
                sMSType.DataType    = "String";
                sMSType.StringValue = "Transactional";

                MessageAttributeValue maxPrice = new MessageAttributeValue();
                maxPrice.DataType    = "Number";
                maxPrice.StringValue = "0.5";

                CancellationTokenSource source = new CancellationTokenSource();
                CancellationToken       token  = source.Token;

                smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID);
                smsAttributes.Add("AWS.SNS.SMS.SMSType", sMSType);
                smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice);

                string message = "Verification code for your Arthur Clive registration request is " + otp;

                PublishRequest publishRequest = new PublishRequest();
                publishRequest.Message           = message;
                publishRequest.MessageAttributes = smsAttributes;
                publishRequest.PhoneNumber       = "+91" + phoneNumber;

                Task <PublishResponse> result = smsClient.PublishAsync(publishRequest, token);
                return("Success");
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("SMSHelper", "SendSMS", ex.Message);
                return("Failed");
            }
        }
예제 #29
0
        /// <summary>
        /// Adds custom attibutes to a sqs message.
        /// </summary>
        /// <param name="customAttributes"></param>
        /// <param name="messageAttributes"></param>
        private void AppendCustomAttributes(Dictionary <string, string> customAttributes, Dictionary <string, MessageAttributeValue> messageAttributes)
        {
            if (customAttributes == null)
            {
                return;
            }

            foreach (var item in customAttributes)
            {
                if (SQSConstants.IsValidAttribute(item.Key))
                {
                    var messageAttributeValue = new MessageAttributeValue
                    {
                        DataType    = "String",
                        StringValue = item.Value
                    };
                    messageAttributes.Add(item.Key, messageAttributeValue);
                }
            }
        }
예제 #30
0
        private SendMessageRequest StoreMessageInS3(SendMessageRequest sendMessageRequest)
        {
            CheckMessageAttributes(sendMessageRequest.MessageAttributes);

            var s3Key              = clientConfiguration.Is3KeyProvider.GenerateName();
            var messageContentStr  = sendMessageRequest.MessageBody;
            var messageContentSize = Encoding.UTF8.GetBytes(messageContentStr).LongCount();

            var messageAttributeValue = new MessageAttributeValue {
                DataType = "Number", StringValue = messageContentSize.ToString()
            };

            sendMessageRequest.MessageAttributes.Add(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);
            var s3Pointer = new MessageS3Pointer(clientConfiguration.S3BucketName, s3Key);

            StoreTextInS3(s3Key, messageContentStr);

            sendMessageRequest.MessageBody = GetJsonFromS3Pointer(s3Pointer);

            return(sendMessageRequest);
        }