private Queue CreateQueue() { var req = new CreateQueueRequest { QueueName = queueName, Attributes = { DelaySeconds = 10, VisibilityTimeout = 30, MaximumMessageSize = 40960, MessageRetentionPeriod = 345600, PollingWaitSeconds = 15 } }; Queue queue = null; try { queue = client.CreateQueue(req); } catch { throw; } return(queue); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="message">消息体</param> /// <param name="publisher">主题</param> private void SendMail(IEventMessage message, Topic publisher) { try { var request = new PublishMessageRequest(); var mailAttrs = new MailAttributes { AccountName = message.Data["AccountName"], // 接件邮箱 Subject = message.Data["Subject"], // 邮件主题 IsHtml = false, ReplyToAddress = false, AddressType = 0 }; var messageAttrs = new MessageAttributes(); messageAttrs.MailAttributes = mailAttrs; request.MessageAttributes = messageAttrs; request.MessageTag = message.Tag; request.MessageBody = message.Body; publisher.PublishMessage(request); // 检查发送结果 var queue = _client.CreateQueue(QueueName); var response = queue.ReceiveMessage(30); XTrace.WriteLine($"发送邮件:{response.Message.Body} "); } catch (Exception ex) { XTrace.WriteLine("发送邮件失败。"); XTrace.WriteException(ex); } }
public AliyunQueue(string queueName) { _client = new MNSClient(_accessKeyId, _secretAccessKey, _endpoint); this._queueName = queueName; try { _queue = _client.GetNativeQueue(_queueName); } catch (Exception ex) { _queue = _client.CreateQueue(queueName); } }
public void SetUp() { client = new Aliyun.MNS.MNSClient(_accessKeyId, _secretAccessKey, _endpoint); client.CreateQueue("UTQueue"); try { client.DeleteQueue("UTQueue2"); } catch (Exception) { // do nothing } }
public void SetUp() { var config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigModel>(File.ReadAllText(@"E:\MNS.json")); _accessKeyId = config.AccessKeyId; _secretAccessKey = config.AccessKey; _endpoint = config.EndPoint; client = new MNSClient(_accessKeyId, _secretAccessKey, _endpoint); client.CreateQueue("UTQueue"); try { client.DeleteQueue("UTQueue2"); } catch (Exception) { // do nothing } }
public void SetAttributesTest() { Queue queue = client.GetNativeQueue("UTQueue"); var resp = queue.GetAttributes(); var originalLoggingEnabled = resp.Attributes.LoggingEnabled; QueueAttributes qa = new QueueAttributes(); queue.SetAttributes(qa); resp = queue.GetAttributes(); Assert.AreEqual(originalLoggingEnabled, resp.Attributes.LoggingEnabled); qa = new QueueAttributes() { LoggingEnabled = false }; queue.SetAttributes(qa); resp = queue.GetAttributes(); Assert.AreEqual(false, resp.Attributes.LoggingEnabled); qa = new QueueAttributes(); queue.SetAttributes(qa); resp = queue.GetAttributes(); Assert.AreEqual(false, resp.Attributes.LoggingEnabled); qa = new QueueAttributes() { LoggingEnabled = true }; queue.SetAttributes(qa); resp = queue.GetAttributes(); Assert.AreEqual(true, resp.Attributes.LoggingEnabled); qa = new QueueAttributes(); queue.SetAttributes(qa); resp = queue.GetAttributes(); Assert.AreEqual(true, resp.Attributes.LoggingEnabled); qa = new QueueAttributes() { LoggingEnabled = true }; var req = new CreateQueueRequest() { QueueName = "UTQueue2", Attributes = qa }; Queue queue2 = client.CreateQueue(req); resp = queue2.GetAttributes(); Assert.AreEqual(true, resp.Attributes.LoggingEnabled); client.DeleteQueue("UTQueue2"); qa = new QueueAttributes() { LoggingEnabled = false }; req = new CreateQueueRequest() { QueueName = "UTQueue2", Attributes = qa }; queue2 = client.CreateQueue(req); resp = queue2.GetAttributes(); Assert.AreEqual(false, resp.Attributes.LoggingEnabled); }