SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
IO::Iron 
Perl Libraries for IronMQ, IronCache and IronWorker 
Mikko Koivunalho 
NORDIC PERL WORKSHOP 2014 
Nov 17th, 2014 / Helsinki
Outline 
Introduction 
Solution 
Our Tools 
Push Queues 
Last 
Questions
Cloud Services 
IronMQ Message Queue 
IronCache Key-value Storage 
IronWorker Worker Queue (uploaded workers)
Nature of Cloud Applications 
Building for Uncertainty 
I The Cloud is everywhere and all the time, but not reliably. 
I In a one-server ("mainframe") environment we can reasonably 
assume that our contact partners or services we use are always on 
and accept our requests. But not in the cloud. There we have no 
control over the services we use. 
I We must: 
1. Assume the other party cannot establish contact with us when we 
need to. 
2. Assume that the execution time and network speed are not constants 
but depend on uncontrollable factors. 
I So it follows: We cannot build tightly connected applications!
Solution? 
I If not tightly-coupled applications then loosely-coupled! 
connection No straight socket connections. 
separation Strict separation of dierent functionality. 
transaction One task: Complete or fail. No between. 
messaging Asynchronous messages between dierent parts of the application. 
I A message queue in the cloud, not tied to one server, not brokering 
of messages between nodes. REST interface. 
I IronMQ
IO::Iron 
CPAN Libraries 
I CPAN: IO::Iron 
I Perl Libraries for IronMQ, IronCache and IronWorker 
I Author: Mikko Koivunalho mikkoi@cpan.org 
I https://metacpan.org/release/IO-Iron 
I Uses REST::Client (LWP) 
I Additional package IO::Iron::Applications contains command line 
interface clients for the same services.
Quickstart I 
I We need the access key (OAuth) from Iron.io. Save it as
le 
'iron.json' for default setup. 
I Sample iron.json: 
f p r o j e c t i d  : XXXXXXXXXXXXXXXXXXXXXXXX , 
 token  : YYYYYYYYYYYYYYYYYYYYYYYYYYY , 
 ho s t  : mqawseuwest 1. i r o n . i o g
Quickstart II 
I Send a message. 
us e IO : : I r o n ; 
r e q u i r e IO : : I r o n : : IronMQ : : Message ; 
my $mq c l i e n t = i ronmq ( ) ; 
my $queue = $mq c l i e n tc r e a t e q u e u e ( ' name ' = ' TestQueue ' ) ; 
my $msg = IO : : I r o n : : IronMQ : : Messagenew( ' body ' = Tes t 
mes sage  ) ; 
my $msg id = $queuepush ( ' mes sages ' = [ $msg ] ) ;
Quickstart III 
I Receive messages. 
us e IO : : I r o n ; 
r e q u i r e IO : : I r o n : : IronMQ : : Message ; 
my $mq c l i e n t = i ronmq ( ) ; 
my $queue = $mq c l i e n tc r e a t e q u e u e ( ' name ' = ' TestQueue ' ) ; 
my @msgs = $queuep u l l ( ' n ' = 1 , ' t imeout ' = 1 ) ; 
f o r e a c h my $msg (@msgs ) f 
p r i n t $msgbody ( ) ; 
g
IO::Iron::IronMQ Interface 
I Divided into two parts: 
I Operations on queues (handled via package IronMQ::Client) 
$ i r o nmq c l i e n t c r e a t e q u e u e ( name = ' ' ) 
$ i r o nmq c l i e n t g e t q u eu e ( name = ' ' ) 
$ i r o nmq c l i e n t upda t e queue ( name = ' ' , ) 
$ i r o nmq c l i e n t d e l e t e q u e u e ( name = ' ' ) 
$ i r o nmq c l i e n t g e t i n f o a b o u t q u e u e ( name = ' ' ) 
$ i r o nmq c l i e n t g e t q u e u e s ( ) 
I Operations on messages (handled via package IronMQ::Queue) 
$queuepush ( ' mes sages ' = [ $msg ] ) ; 
$queuep u l l ( n = 10 , t imeout = 120 ) ; 
$queuepeek ( n = 10 ) ; 
$queued e l e t e ( ' i d s ' = [ $msg id ] ) ; 
$queuer e l e a s e ( ' i d ' = $msg id , ' d e l a y ' = $ d e l a y ) ; 
$queuetouch ( ' i d ' = $msg id ) ; 
$queuec l e a r ( ) ; 
$queues i z e ( ) ;
IronMQ::Queue 
I IO::Iron::IronMQ::Queue objects are created by the client 
IO::Iron::IronMQ::Client. 
I With an IO::Iron::IronMQ::Queue object you can push messages to 
the queue, or pull messages from it. 
I The names push and pull are used because the queue is likened to a 
pipe. The queue is like a FIFO pipe (
rst in,
rst out). 
I Operations are atomic and messages will be read in the same order 
as they were sent.
IronMQ::Message 
I A message (an object of class IO::Iron::IronMQ::Message) will 
contain the following parameters: 
body Free text string. Serialized object (JSONized). 
timeout When reading from queue, after timeout (in seconds), item will be 
placed back onto queue. 
delay The item will not be available on the queue until this amount of 
seconds have passed. 
expires in How long in seconds to keep the item on the queue before it is 
deleted. Useful for, e.g. alarm queues. 
id Message id from IronMQ (available after message has been 
pulled/peeked). 
r e q u i r e IO : : I r o n : : IronMQ : : Message ; 
r e q u i r e JSON : : MaybeXS ; 
my $ j s o n = JSON : : MaybeXSnew( u t f 8 = 1 , p r e t t y = 1) ; 
my %msg body hash = ( ms g body t e x t = 'My mes sage #01 ' , 
msg body i t em = f s u b i t em = ' Sub t e x t ' g) ; 
my $msg body = $j sonencode (n%msg body hash ) ; 
my $msg = IO : : I r o n : : IronMQ : : Messagenew( ' body ' =$msg body , 
' t imeout ' = 60 , ' d e l a y ' = 0 , ' e x p i r e s i n ' = 60 , 
) ;
Push Queues I 
Delivery to Front Door 
I One of IronMQ's outstanding features are push queues. 
I Instead of polling a message queue, you can set subscribers to a 
queue. 
I Subscribers are simply URL's that IronMQ will post to whenever a 
message is posted to your queue. There are currently three types 
subscribers supported, all dierentiated by the URL scheme (
rst 
part of the URL): 
1. HTTP endpoints: urls with the http or https pre
x for instance, 
2. http://myapp.com/some/endpoint or 
https://myapp.com/some/endpoint. 
3. IronMQ endpoints: IronMQ endpoints point to another queue on 
IronMQ. Use these to do fan-out to multiple queues. 
4. IronWorker endpoints: IronWorker endpoints will

Weitere ähnliche Inhalte

Was ist angesagt?

What's New in Swift 4
What's New in Swift 4What's New in Swift 4
What's New in Swift 4Young Hoo Kim
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streamsBartosz Sypytkowski
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3Luciano Mammino
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)tarcieri
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныTimur Safin
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to RakuSimon Proctor
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Ransomware for fun and non-profit
Ransomware for fun and non-profitRansomware for fun and non-profit
Ransomware for fun and non-profitYouness Zougar
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2Alessandro Molina
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen OomsAjay Ohri
 

Was ist angesagt? (20)

What's New in Swift 4
What's New in Swift 4What's New in Swift 4
What's New in Swift 4
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
Current State of Coroutines
Current State of CoroutinesCurrent State of Coroutines
Current State of Coroutines
 
Book
BookBook
Book
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
 
bluespec talk
bluespec talkbluespec talk
bluespec talk
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Ransomware for fun and non-profit
Ransomware for fun and non-profitRansomware for fun and non-profit
Ransomware for fun and non-profit
 
Codable routing
Codable routingCodable routing
Codable routing
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen Ooms
 

Ähnlich wie IO::Iron

So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...doughellmann
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerIslam Sharabash
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logsStefan Krawczyk
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With PythonLuca Mearelli
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solrLucidworks (Archived)
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worldsChristopher Spring
 
Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsMarian Marinov
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008eComm2008
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 

Ähnlich wie IO::Iron (20)

So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logs
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With Python
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solr
 
Lab
LabLab
Lab
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your plugins
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Embedding perl
Embedding perlEmbedding perl
Embedding perl
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Performance patterns
Performance patternsPerformance patterns
Performance patterns
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 

Kürzlich hochgeladen

COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfVictor Lopez
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Soroosh Khodami
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfDeskTrack
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfWSO2
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...OnePlan Solutions
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesNeo4j
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024Shane Coughlan
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfQ-Advise
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionMohammed Fazuluddin
 

Kürzlich hochgeladen (20)

COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 

IO::Iron

  • 1. IO::Iron Perl Libraries for IronMQ, IronCache and IronWorker Mikko Koivunalho NORDIC PERL WORKSHOP 2014 Nov 17th, 2014 / Helsinki
  • 2. Outline Introduction Solution Our Tools Push Queues Last Questions
  • 3. Cloud Services IronMQ Message Queue IronCache Key-value Storage IronWorker Worker Queue (uploaded workers)
  • 4. Nature of Cloud Applications Building for Uncertainty I The Cloud is everywhere and all the time, but not reliably. I In a one-server ("mainframe") environment we can reasonably assume that our contact partners or services we use are always on and accept our requests. But not in the cloud. There we have no control over the services we use. I We must: 1. Assume the other party cannot establish contact with us when we need to. 2. Assume that the execution time and network speed are not constants but depend on uncontrollable factors. I So it follows: We cannot build tightly connected applications!
  • 5. Solution? I If not tightly-coupled applications then loosely-coupled! connection No straight socket connections. separation Strict separation of dierent functionality. transaction One task: Complete or fail. No between. messaging Asynchronous messages between dierent parts of the application. I A message queue in the cloud, not tied to one server, not brokering of messages between nodes. REST interface. I IronMQ
  • 6. IO::Iron CPAN Libraries I CPAN: IO::Iron I Perl Libraries for IronMQ, IronCache and IronWorker I Author: Mikko Koivunalho mikkoi@cpan.org I https://metacpan.org/release/IO-Iron I Uses REST::Client (LWP) I Additional package IO::Iron::Applications contains command line interface clients for the same services.
  • 7. Quickstart I I We need the access key (OAuth) from Iron.io. Save it as
  • 8. le 'iron.json' for default setup. I Sample iron.json: f p r o j e c t i d : XXXXXXXXXXXXXXXXXXXXXXXX , token : YYYYYYYYYYYYYYYYYYYYYYYYYYY , ho s t : mqawseuwest 1. i r o n . i o g
  • 9. Quickstart II I Send a message. us e IO : : I r o n ; r e q u i r e IO : : I r o n : : IronMQ : : Message ; my $mq c l i e n t = i ronmq ( ) ; my $queue = $mq c l i e n tc r e a t e q u e u e ( ' name ' = ' TestQueue ' ) ; my $msg = IO : : I r o n : : IronMQ : : Messagenew( ' body ' = Tes t mes sage ) ; my $msg id = $queuepush ( ' mes sages ' = [ $msg ] ) ;
  • 10. Quickstart III I Receive messages. us e IO : : I r o n ; r e q u i r e IO : : I r o n : : IronMQ : : Message ; my $mq c l i e n t = i ronmq ( ) ; my $queue = $mq c l i e n tc r e a t e q u e u e ( ' name ' = ' TestQueue ' ) ; my @msgs = $queuep u l l ( ' n ' = 1 , ' t imeout ' = 1 ) ; f o r e a c h my $msg (@msgs ) f p r i n t $msgbody ( ) ; g
  • 11. IO::Iron::IronMQ Interface I Divided into two parts: I Operations on queues (handled via package IronMQ::Client) $ i r o nmq c l i e n t c r e a t e q u e u e ( name = ' ' ) $ i r o nmq c l i e n t g e t q u eu e ( name = ' ' ) $ i r o nmq c l i e n t upda t e queue ( name = ' ' , ) $ i r o nmq c l i e n t d e l e t e q u e u e ( name = ' ' ) $ i r o nmq c l i e n t g e t i n f o a b o u t q u e u e ( name = ' ' ) $ i r o nmq c l i e n t g e t q u e u e s ( ) I Operations on messages (handled via package IronMQ::Queue) $queuepush ( ' mes sages ' = [ $msg ] ) ; $queuep u l l ( n = 10 , t imeout = 120 ) ; $queuepeek ( n = 10 ) ; $queued e l e t e ( ' i d s ' = [ $msg id ] ) ; $queuer e l e a s e ( ' i d ' = $msg id , ' d e l a y ' = $ d e l a y ) ; $queuetouch ( ' i d ' = $msg id ) ; $queuec l e a r ( ) ; $queues i z e ( ) ;
  • 12. IronMQ::Queue I IO::Iron::IronMQ::Queue objects are created by the client IO::Iron::IronMQ::Client. I With an IO::Iron::IronMQ::Queue object you can push messages to the queue, or pull messages from it. I The names push and pull are used because the queue is likened to a pipe. The queue is like a FIFO pipe (
  • 14. rst out). I Operations are atomic and messages will be read in the same order as they were sent.
  • 15. IronMQ::Message I A message (an object of class IO::Iron::IronMQ::Message) will contain the following parameters: body Free text string. Serialized object (JSONized). timeout When reading from queue, after timeout (in seconds), item will be placed back onto queue. delay The item will not be available on the queue until this amount of seconds have passed. expires in How long in seconds to keep the item on the queue before it is deleted. Useful for, e.g. alarm queues. id Message id from IronMQ (available after message has been pulled/peeked). r e q u i r e IO : : I r o n : : IronMQ : : Message ; r e q u i r e JSON : : MaybeXS ; my $ j s o n = JSON : : MaybeXSnew( u t f 8 = 1 , p r e t t y = 1) ; my %msg body hash = ( ms g body t e x t = 'My mes sage #01 ' , msg body i t em = f s u b i t em = ' Sub t e x t ' g) ; my $msg body = $j sonencode (n%msg body hash ) ; my $msg = IO : : I r o n : : IronMQ : : Messagenew( ' body ' =$msg body , ' t imeout ' = 60 , ' d e l a y ' = 0 , ' e x p i r e s i n ' = 60 , ) ;
  • 16. Push Queues I Delivery to Front Door I One of IronMQ's outstanding features are push queues. I Instead of polling a message queue, you can set subscribers to a queue. I Subscribers are simply URL's that IronMQ will post to whenever a message is posted to your queue. There are currently three types subscribers supported, all dierentiated by the URL scheme (
  • 17. rst part of the URL): 1. HTTP endpoints: urls with the http or https pre
  • 18. x for instance, 2. http://myapp.com/some/endpoint or https://myapp.com/some/endpoint. 3. IronMQ endpoints: IronMQ endpoints point to another queue on IronMQ. Use these to do fan-out to multiple queues. 4. IronWorker endpoints: IronWorker endpoints will
  • 19. re up an IronWorker task with the message body as the payload.
  • 20. Push Queues II my $push queue = $ i r o n mq c l i e n t upda t e queue ( ' name ' = 'My Message Queue ' , ' s u b s c r i b e r s ' = [ f u r l = i ronmq :/// Other queue name g , f u r l = ht tp : / /my . s e r v e r g , ] , ' p u s h t y p e ' = ' mu l t i c a s t ' , ' r e t r i e s ' = 0 , ' r e t r i e s d e l a y ' = 3 , ' e r r o r q u e u e ' = Er ror queue name , ) ; I Get push status for a message. my $ i n f o = $i ron mq queueg e t p u s h s t a t u s ( ' i d ' = $msg id ) ; my @s u b s c r i b e r s = (@f i n f o f ' s u b s c r i b e r s ' gg) ;
  • 21. Push Queues III I Acknowledge / Delete Push Message for a Subscriber. I This is only for use with long running processes that have previously returned a 202 (Request accepted, processing delayed or takes a long time). my $push acknowl edged = $queued e l e t e p u s h me s s a g e ( ' i d ' = $msg id , ' s u b s c r i b e r ' = $ s u b s c r i b e r s [0]f ' i d ' g ) ;
  • 22. Push Queues IV I Add Subscribers to a Queue. my $ a d d r e t v a l = $queuea d d s u b s c r i b e r s ( ' name ' = $queue name , ' s u b s c r i b e r s ' = [ f ' u r l ' = i ronmq : / / p r o j e c t i d : token n@hos t / queue name g , f ' u r l ' = i ronmq :/// $queue name 02 g , ] , ) ; I Remove Subscribers from a Queue my $ d e l r e t v a l = $ i r o n mq c l i e n t d e l e t e s u b s c r i b e r s ( ' name ' = $queue name , ' s u b s c r i b e r s ' = [ f ' u r l ' = i ronmq :/// $queue name g , ] , ) ;
  • 23. Logging and Debugging I Package IO::Iron uses Log::Any for logging. I Every atomic action (with Iron.io remote services) and a few other actions produce a log entry. I Log entries can be routed to a compatible logger with Log::Any::Adapter. I Log::Any is also used to output logging verbose/debugging log entries. I Just raise the throughput level to 'debug' or 'trace'. I Trace will output the entry and exit points of almost every functions, together with function parameters and return values. If you need a quick and dirty solution, try this at the beginning of a
  • 24. le: us e Log : : Any : : Tes t ; # s h o u l d appear b e f o r e ' us e Log : : Any ' ! us e Log : : Any qw( $ l o g ) ; us e Log : : Any : : Adapter ( ' S t d e r r ' ) ;
  • 25. Questions Questions? And maybe answers