public void Publish <T>(T message, string subject) { try { if (string.IsNullOrEmpty(subject)) { _client.Publish(new PublishRequest { Message = JsonConvert.SerializeObject(message), TopicArn = _awsTopicArn }); } else { _client.Publish(new PublishRequest { Subject = subject, Message = JsonConvert.SerializeObject(message), TopicArn = _awsTopicArn }); } } catch (Exception e) { _logger.ErrorFormat("Couldn't publish {0} to topic {1}", subject, _awsTopicArn, e); } }
protected override void Write(LogEventInfo logEvent) { var logMessage = Layout.Render(logEvent); var subject = Subject.Render(logEvent); var count = Encoding.UTF8.GetByteCount(logMessage); if (count > ConfiguredMaxMessageSizeInBytes) { if (InternalLogger.IsWarnEnabled) { InternalLogger.Warn("logging message will be truncted. original message is\n{0}", logMessage); } logMessage = logMessage.LeftB(TransferEncoding, truncateSizeInBytes) + TruncateMessage; } try { client.Publish(new PublishRequest() { Message = logMessage, Subject = subject, TopicArn = TopicArn }); } catch (AmazonSimpleNotificationServiceException e) { InternalLogger.Fatal("RequstId: {0},ErrorType: {1}, Status: {2}\nFailed to send log with\n{3}\n{4}", e.RequestId, e.ErrorType, e.StatusCode, e.Message, e.StackTrace); } }
public JsonResult Submit(FormData data) { List <PublishResponse> publishResponses = new List <PublishResponse>(); string accessKey = GetConfigValue("AWSAccessKeyId"); string secretKey = GetConfigValue("AWSSecretKeyValue"); var client = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1); var request = new ListTopicsRequest(); // only want the ContactUs Topic Arn // for now this is hard-coded - future refactor should place it in web config or database. // Looks like IAWSChannelLoader etc got wiped. For now, just run with web.config string contactUsARN = GetConfigValue("AWContactUsARN"); /* Only one ARN, so following proof of concept not needed, commented out * var listTopicsResponse = client.ListTopics(request); * foreach (var topic in listTopicsResponse.Topics) * { * * } */ // Basic functionality works. Need to parse the publishResponse collection for specific service messages (failed, success, etc) // but for now simply assume if it published it was a success. publishResponses.Add(client.Publish(new PublishRequest { TopicArn = contactUsARN, Message = data.ToString() })); return(Json(publishResponses, JsonRequestBehavior.AllowGet)); }
public static void sendMessage(User user, MessageTypeEnum type) { if (user.first_name == "control") { return; } AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(AWSConstants.SNS_ACCESS_KEY, AWSConstants.SNS_SECRET_ACCESS_KEY, Amazon.RegionEndpoint.USEast1); PublishRequest pubRequest = new PublishRequest(); // get the message that corresponds to the type of notification pubRequest.Message = MessageTypeExtension.GetDescription(type); // sending sms message if (user._Notification_Type == NotificationTypeEnum.SMS || user._Notification_Type == NotificationTypeEnum.ALL) { // we need to have +1 on the beginning of the number in order to send if (user.phone_number.Substring(0, 2) != "+1") { pubRequest.PhoneNumber = "+1" + user.phone_number; } else { pubRequest.PhoneNumber = user.phone_number; } PublishResponse pubResponse = snsClient.Publish(pubRequest); Console.WriteLine(pubResponse.MessageId); } }
static void Main(string[] args) { /* Topic ARNs must be in the correct format: * arn:aws:sns:REGION:ACCOUNT_ID:NAME * * where: * REGION is the region in which the topic is created, such as us-west-2 * ACCOUNT_ID is your (typically) 12-character account ID * NAME is the name of the topic */ string topicArn = args[0]; string message = "Hello at " + DateTime.Now.ToShortTimeString(); var client = new AmazonSimpleNotificationServiceClient(region: Amazon.RegionEndpoint.USWest2); var request = new PublishRequest { Message = message, TopicArn = topicArn }; try { var response = client.Publish(request); Console.WriteLine("Message sent to topic:"); Console.WriteLine(message); } catch (Exception ex) { Console.WriteLine("Caught exception publishing request:"); Console.WriteLine(ex.Message); } }
static void Main(string[] args) { // US phone numbers must be in the correct format: // +1 (nnn) nnn-nnnn OR +1nnnnnnnnnn string number = args[0]; string message = "Hello at " + DateTime.Now.ToShortTimeString(); var client = new AmazonSimpleNotificationServiceClient(region: Amazon.RegionEndpoint.USWest2); var request = new PublishRequest { Message = message, PhoneNumber = number }; try { var response = client.Publish(request); Console.WriteLine("Message sent to " + number + ":"); Console.WriteLine(message); } catch (Exception ex) { Console.WriteLine("Caught exception publishing request:"); Console.WriteLine(ex.Message); } }
/** * 2. send push message */ public int SendMessage(string endpointArn, string rawMessage) { try { log.InfoFormat("function:SendMessage: Sending message to Endpoint:{0}", endpointArn); var resp = client.Publish(new PublishRequest() { MessageStructure = "json", TargetArn = endpointArn, Message = rawMessage }); } catch (EndpointDisabledException e) { log.InfoFormat("function:SendMessage: Endpoint Disabled, deleting Endpoint:{0}", endpointArn); client.DeleteEndpoint(new DeleteEndpointRequest() { EndpointArn = endpointArn }); return(-1); } catch (Exception e) { log.InfoFormat("function:SendMessage: Unknown error: {0}, message: {1}", e, rawMessage); return(-9999); } return(0); }
public bool Send() { bool status = true; try { AmazonSimpleNotificationServiceClient smsClient = new AmazonSimpleNotificationServiceClient(security.AccessKeyId, security.SecretKeyId, security.Region); PublishRequest request = new PublishRequest(); PublishResponse response = new PublishResponse(); Dictionary <string, MessageAttributeValue> attributes = new Dictionary <string, MessageAttributeValue>(); attributes.Add("AWS.SNS.SMS.SenderID", new MessageAttributeValue() { DataType = "String", StringValue = settings.SenderId }); attributes.Add("AWS.SNS.SMS.SMSType", new MessageAttributeValue() { DataType = "String", StringValue = settings.SMSType }); attributes.Add("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue() { DataType = "String", StringValue = settings.MaxPrice.ToString() }); request.MessageAttributes = attributes; request.PhoneNumber = message.MobileNo; request.Message = message.Message; response = smsClient.Publish(request); } catch (Exception ex) { status = false; } return(status); }
// public List<PublishResponse> Submit(FormData data) public async Task <IHttpActionResult> Submit(FormatException data) { IHttpActionResult result = null; string accessKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString(); string secretKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString(); var client = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1); var request = new ListTopicsRequest(); var listTopicsResponse = client.ListTopics(request); List <PublishResponse> publishResponses = new List <PublishResponse>(); foreach (var topic in listTopicsResponse.Topics) { publishResponses.Add(client.Publish(new PublishRequest { TopicArn = topic.TopicArn, Message = "This is a test from the ContactUs Web MVC Controller" }) ); } return(result); }
public static void PublishMessage(string topicArn, string message, string subject = null) { using (var client = new AmazonSimpleNotificationServiceClient(Settings.AccessKey, Settings.Secret)) { client.Publish(topicArn, message, subject); } }
public bool ConfirmUser(string accountConfirmationToken) { var confirmed = false; User user; logger.Log(LogLevel.Info, string.Format("Confirming User Registration with Email Token {0}. Starting.", accountConfirmationToken)); if (string.IsNullOrEmpty(accountConfirmationToken)) { logger.Log(LogLevel.Error, string.Format("Confirming User Registration with Email Token {0}. No confirmation token.", accountConfirmationToken)); throw CreateArgumentNullOrEmptyException("accountConfirmationToken"); } using (Context context = new Context()) { user = _ctx.Users.FirstOrDefault(Usr => Usr.ConfirmationToken.Equals(accountConfirmationToken)); if (user == null) { logger.Log(LogLevel.Error, string.Format("Confirming User Registration with Email Token {0}. Unable to find user associated with account token.", accountConfirmationToken)); return(false); } confirmed = true; user.IsConfirmed = true; _ctx.SaveChanges(); } if (!confirmed) { return(false); } logger.Log(LogLevel.Info, string.Format("Confirming User Registration with Email Token {0}. Calling Workflow.", accountConfirmationToken)); try { logger.Log(LogLevel.Info, string.Format("Confirming User Registration with Email Token {0}. Calling Amazon SNS.", accountConfirmationToken)); AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(); client.Publish(new PublishRequest() { Message = user.UserId.ToString(), TopicArn = ConfigurationManager.AppSettings["UserPostedTopicARN"], Subject = "New User Registration" }); } catch (Exception ex) { logger.Log(LogLevel.Info, string.Format("Confirming User Registration with Email Token {0}. Exception {1}.", accountConfirmationToken, ex.Message)); return(false); } logger.Log(LogLevel.Info, string.Format("Confirming User Registration with Email Token {0}. Ending.", accountConfirmationToken)); return(true); }
public void Publish(Message message) { var request = new PublishRequest(); request.TopicArn = TopicArn; request.Message = AwsMessage.Wrap(message); var response = _snsClient.Publish(request); }
public bool SendSms(string group, string message) { string topicArn = GetTopic(group); PublishRequest req = new PublishRequest(topicArn, message); PublishResponse res = client.Publish(req); return(true); }
public void PublishNotification(string topic, string message) { snsClient.Publish(new PublishRequest { Message = message, TargetArn = topic }); }
public static void Publish(string topic, string jsonObject) { using (var snsClient = new AmazonSimpleNotificationServiceClient(AccessKey, SecretKey, RegionEndpoint.GetBySystemName(Region))) { var topicArn = BaseTopicArn + topic; PublishRequest publishRequest = new PublishRequest(topicArn, jsonObject); snsClient.Publish(publishRequest); } }
public void publish(string team, DateTime timestamp) { OutboundMessage message = new OutboundMessage(); message.team = team; TimeSpan d = DateTime.Now.ToUniversalTime() - timestamp; message.time = d.Ticks; client.Publish(Resources.topicARN, JsonConvert.SerializeObject(message)); }
public void PublishToTopic(string topicArn, string subject, string message) { Console.WriteLine(); Console.WriteLine($"Publishing message to topic - {topicArn}"); sns.Publish(new PublishRequest { Subject = subject, Message = message, TopicArn = topicArn }); }
private void PublishSNSEvent(string Message, string AmazonSNSKey, string AmazonSNSSecretKey, string TopicName, string EventType) { string topicname = ProcessSNSTopicName(TopicName); try { var client = new AmazonSimpleNotificationServiceClient(AmazonSNSKey, AmazonSNSSecretKey); string topicarn = string.Empty; PublishResult publishResult = new PublishResult(); if (IsTopicExists(client, topicname, out topicarn)) { PublishRequest publishRequest = new PublishRequest(); publishRequest.Message = Message; publishRequest.TopicArn = topicarn; PublishResponse publishResponse = client.Publish(publishRequest); publishResult = publishResponse.PublishResult; } else { CreateTopicRequest topicRequest = new CreateTopicRequest(); topicRequest.Name = topicname; CreateTopicResponse topicResponse = client.CreateTopic(topicRequest); CreateTopicResult result = topicResponse.CreateTopicResult; PublishRequest publishRequest = new PublishRequest(); publishRequest.Message = Message; publishRequest.TopicArn = result.TopicArn; PublishResponse publishResponse = client.Publish(publishRequest); publishResult = publishResponse.PublishResult; } if (!string.IsNullOrEmpty(publishResult.MessageId)) { CreateLogs(Message, EventType, topicname, true); } } catch (AmazonSimpleNotificationServiceException ex) { /*Log details to logentries server.*/ CreateLogs(Message, EventType, topicname, false); throw ex; } }
public static void pushMessage(string message, string topicArn) { Console.WriteLine("Publishing message to topic..."); var sns = new AmazonSimpleNotificationServiceClient(); sns.Publish(new PublishRequest { Subject = "Test", Message = message, TopicArn = topicArn }); }
public static void Main(string[] args) { var sns_object = new AmazonSimpleNotificationServiceClient(); string email_id = "*****@*****.**"; try { // Create an SNS topic called "PACKT-PUB" Console.WriteLine("Creating topic..."); var Topic_Arn_id = sns_object.CreateTopic(new CreateTopicRequest { Name = "PACKT-PUB" }).TopicArn; // Set attributes for the topic sns_object.SetTopicAttributes(new SetTopicAttributesRequest { TopicArn = Topic_Arn_id, AttributeName = "DisplayName", AttributeValue = "PACKT-PUB" }); // Add an email subsciption sns_object.Subscribe(new SubscribeRequest { TopicArn = Topic_Arn_id, Protocol = "email", Endpoint = email_id }); // Publish a topic sns_object.Publish(new PublishRequest { Subject = "Test", Message = "Testing testing 1 2 3", TopicArn = Topic_Arn_id }); Console.WriteLine("Waiting 60 seconds before deleting the topic"); System.Threading.Thread.Sleep(30000); //Delete the topic sns_object.DeleteTopic(new DeleteTopicRequest { TopicArn = Topic_Arn_id }); } catch (AmazonSimpleNotificationServiceException exception) { Console.WriteLine("Error !"); Console.WriteLine(exception.ErrorCode); } }
static void SendSNSMessages(int numberOfMsg, double intervalBetweenMsg) { for (int i = 0; i < numberOfMsg; ++i) { String msg = String.Format("This SNS message [{0}] from C# application", i); PublishRequest req = new PublishRequest(SNS_TOPIC, msg); PublishResponse resp = _snsClient.Publish(req); Console.WriteLine("Message is sent, MessageId: " + resp.MessageId); Thread.Sleep((int)(intervalBetweenMsg * 1000)); } }
public void Send(string phone, string message) { AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USEast1); PublishRequest pubRequest = new PublishRequest { Message = message, PhoneNumber = phone, }; // add optional MessageAttributes, for example: // pubRequest.MessageAttributes.Add("AWS.SNS.SMS.SenderID", new MessageAttributeValue // { StringValue = "SenderId", DataType = "String" }); PublishResponse pubResponse = snsClient.Publish(pubRequest); }
public void Publish <TDomainEvent>(TDomainEvent @event) where TDomainEvent : IDomainEvent { var payload = _config.EllemyConfiguration.Serializer.Serialize(@event); var request = new PublishRequest { Message = payload, Subject = @event.GetType().FullName, TopicArn = _topicArn }; _client.Publish(request); }
public virtual void PublishTopicMessage(AmazonSimpleNotificationServiceClient snsClient, string topicArn, string subject, string message) { // Create the request var publishRequest = new PublishRequest { Subject = subject, Message = message, TopicArn = topicArn }; // Submit the request snsClient.Publish(publishRequest); }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="message">The message.</param> public void Send(Message message) { var messageString = JsonConvert.SerializeObject(message); _logger.DebugFormat("SQSMessageProducer: Publishing message with topic {0} and id {1} and message: {2}", message.Header.Topic, message.Id, messageString); using (var client = new AmazonSimpleNotificationServiceClient()) { var topicArn = EnsureTopic(message.Header.Topic, client); var publishRequest = new PublishRequest(topicArn, messageString); client.Publish(publishRequest); } }
public void SendPush(string endpointArn, string msg) { if (string.IsNullOrEmpty(endpointArn)) { throw new Exception("Endpoint ARN was null"); } var pushMsg = new PublishRequest(); pushMsg.Message = msg; pushMsg.TargetArn = endpointArn; _client.Publish(pushMsg); }
private static void PublishMessage(AmazonSimpleNotificationServiceClient sns, string topicArn, string subject, string message) { Console.WriteLine(); Console.WriteLine("Publishing message to topic..."); sns.Publish(new PublishRequest { Subject = subject, Message = message, TopicArn = topicArn }); // Verify email receieved Console.WriteLine(); Console.WriteLine("Please check your email and press enter when you receive the message..."); Console.ReadLine(); }
public void PublishToTopic() { PublishRequest request = new PublishRequest { TopicArn = TopicARN, Subject = "New Topic Message", Message = "New Message" }; var response = client.Publish(request); if (response.HttpStatusCode.IsSuccess()) { Console.WriteLine("Message sent successfully"); Console.WriteLine($"MessageId: {response.MessageId}"); } }
public void PublishToTopic() { PublishRequest request = new PublishRequest { TopicArn = "arn:aws:sns:us-west-1:491483104165:TopicApp", Subject = "New Topic Message", Message = "New Message" }; var response = client.Publish(request); if (response.HttpStatusCode.IsSuccess()) { Console.WriteLine($"Message sent successfullt! \nMessageId: {response.MessageId}"); } }
public override void Send(Message message) { if (Pattern == MessagePattern.PublishSubscribe) { var publishRequest = new PublishRequest(); publishRequest.Message = message.ToJsonString(); publishRequest.TopicArn = Address; _snsClient.Publish(publishRequest); } else { var sendRequest = new SendMessageRequest(); sendRequest.MessageBody = message.ToJsonString(); sendRequest.QueueUrl = Address; _sqsClient.SendMessage(sendRequest); } }