开发区域

The Advanced Software Development with MATLAB

从MATLAB通知

Waiting for a computer or cluster to finish a task is about as exciting as watching paint dry. XKCD even has a comic about it.

XKCD

MATLAB developers, deal with heavy computational loads,, running for long periods of time and involving lots of data. There are many situations where I stand up and stretch or perhaps get myself another refill of coffee, a beverage that I love almost to a fault.

系统通知我的进展,完成或错误,使我远离我的屏幕并返回有效。不是很好如果我能通知路线,开始下一个任务?或者让整个团队知道构建或测试活动的状态。这正是AWS简单通知系统(SNS)Comes in.

In this post, I will describe how MathWorks developers canLeverage cloud "capabilitiesAnd quickly setup a fully managed publication/subscription (pub/sub) messaging system. Once configured, it order to enable push -based messaging from MATLAB.

这篇文章背后的代码已被释放github.com一旦被设置为/的工具The installation instructions, it becomes trivial to define fan - out topologies and set up the MATLAB to handle the notifications for myself as well as - teams.

作为一个例子,MATLAB调用提供了性能基准测试函数板凳上. My this is a contrived workload let me instruct it to run the performance benchmark 200 times. On my local computer, this is a test that takes about 20 mins. Just enough time for me to get a nice cup of coffee and stretch as MATLAB does the heavy lifting.

Bench (200);

The Setup of the topic:

First, let me setup a topic on SNS. This is one - time operation. A topic defines a logical address point which ACTS as the communication channel. It allows me to group multiple endpoints. These endpoints can be simple like E-mail and SMS or more complex HTTP (s) like calls to the servers, AWS Lambda functions provides the or the Queues.

SNS = aws. SNS. The Client ();SNS. The initialize;Topic = SNS. CreateTopic ('coffee - notification');

Each topic comes with a unique identifier called the anARN.

这很容易查询:

TopicARN = topic. GetTopicArn;TopicARN ='arn: aws: SNS: us - west - "4 [REDACTED] 02: coffee - notification'

The Subscription of the endpoints:

For the next installment, let us assume that the I wish MATLAB to send me a text message AND send me an email when my benchmarks are complete. This is the setup in what lines of code. This, again, is a one - time operation as I define the topology of which endpoints to subscribe to my topic.

SNS. The subscribe (topicARN,“电子邮件”,“啊* * * * ra@mathworks.com”);SNS. The subscribe (topicARN,'the SMS',“+ 12485555555”);

简而言之,我们所做的,到目前为止,是我电子邮件和手机订阅我们创建的主题。更多的是可能的但让我保持这个插图简单。

Send a Notification:

我所有的订阅端点发送一个通知是一行的MATLAB代码来完成。现在的我的基准测试代码看起来像:

Bench (200);SNS. The publish (topicARN,'the Benchmark complete!');

Hit the run!...And now to go get that cup of coffee.

Sure enough, 20 minutes later, I get notified on my cellphone and email:

短信

Ok, the use of this tooling as a coffee break notifier is a trivial use - case to illustrateenrollment a point. The tooling to the as this gets particularly useful when building bigger systems where the notification can trigger downstream actions to as the generation of reports, etc.

The functionality really begins to shine in use - cases where The notification system needs to scale to hundreds or thousands of subscriber endpoints. These notifications can be consumed by humans and other apps/services alike. This pub - sub pattern is common in building service oriented systems, where it is 2 interconnect marketers technology sports.

So, what are you planning to do with your MATLAB?Fit above it call you back from your coffee break?




Published with MATLAB ® R2019b

|

comments

要发表评论,请点击here登录到您的MathWorks帐户或创建一个新帐户。