SlideShare uma empresa Scribd logo
1 de 52
31/03/2022
Warsaw MuleSoft Meetup Group
Effective Streaming in Mule 4
● Introductions & Community Updates
● Effective Streaming in Mule 4
● Quiz & Lottery
Agenda
2
Introduction
Our partners
4
● IT Expert at Roche
● More than 21 years of experience in IT
● MuleSoft Certifications: MCIA, MCPA, MCD
● Salesforce Certifications: Administrator, Platform App Builder,
Platform Developer I
● I like technology :)
https://www.linkedin.com/in/jacekbialecki/
5
Jacek Białecki
Speaker
● Subject Matter Expert at PwC Poland
● MuleSoft Ambassador
● MuleSoft Meetup Leader for Warsaw, Poland
● Working with MuleSoft products for over 10 years now
● One of Salesforce Trailblazers
https://trailhead.salesforce.com/trailblazers/patryk-bandurski
Organizer
Check out my integration blog
https://ambassadorpatryk.com/blog
6
Share the event
● Share the Meetup in your social media
● Tag the event using
#MuleSoftMeetup
#WarsawMuleSoftMeetup
Thanks ☺
7
Lottery
● How it works?
○ During the event randomly is selected a winner
among the present attendees.
○ One winner at a time!
○ Three winners at the event
○ I will ask winners to send me Direct Message with
email address
● Prize is sponsored by
Three winners of today’s
lottery receives:
Amazon Voucher for 30$
8
Go to www.menti.com and use the code 9155 3697
Community Update
TDX'22
10
MuleSoft Meetups
Upcoming MuleSoft Meetups
Follwow Mariana Lemus
profile on Linkedin
Follow MuleSoft Community group on
Linkedin
11
All contents © MuleSoft, LLC
Effective Streaming in Mule 4
All contents © MuleSoft, LLC
Agenda
● Introduction to Streams
● Streams in Mule 4
● DEMO
● Streaming in DataWeave
● DEMO
● Summary & performance considerations
All contents © MuleSoft, LLC
Introduction to Streams
All contents © MuleSoft, LLC
Concept of Streams
Scenario - read whole input to the memory
All contents © MuleSoft, LLC
Concept of Streams
Scenario - read whole input to the memory
Problem: MEMORY CONSUMPTION
Out Of
Memory
All contents © MuleSoft, LLC
Concept of Streams
Scenario – splitting files
All contents © MuleSoft, LLC
Concept of Streams
Scenario - pagination
https://api.com/items?offset=200&limit=100
All contents © MuleSoft, LLC
Concept of Streams
Scenario - read data as a stream
All contents © MuleSoft, LLC
This is (also) a stream :)
All contents © MuleSoft, LLC
Streams in Mule 4
All contents © MuleSoft, LLC
Streams in MuleSoft 4:
● Non-Repeatable Streams (available in Mule 3)
● In-Memory Repeatable Stream (new in Mule 4)
● File-Stored Repeatable Stream (new in Mule 4)
All contents © MuleSoft, LLC
Streams in MuleSoft 4: Non-Repeatable Streams
● Cannot be read more than once
● Cannot be consumed simultaneously
● Very performant but needs careful treatment
○ No additional memory buffers
○ No I/O operations (disk based buffers)
● Suitable for processing LARGE streams
All contents © MuleSoft, LLC
Streams in MuleSoft 4: Non-repeatable Streams
● Cannot be read more than once (examples)
All contents © MuleSoft, LLC
Streams in MuleSoft 4: Non-repeatable Streams
● Cannot be consumed simultaneously (example)
All contents © MuleSoft, LLC
New in Mule 4: In-Memory Repeatable Stream
All contents © MuleSoft, LLC
New in Mule 4: File-Stored Repeatable Stream
Uses KRYO serializer. Better than standard Java serializer but
still cannot serialize everything
A typical case is a POJO containing an
org.apache.xerces.jaxp.datatype.XMLGregorianCale
ndarImpl, which is in use in the NetSuite or Microsoft Dynamics
CRM connectors.
Only available in
Mule Enterprise
Edition (Mule EE)
All contents © MuleSoft, LLC
Stream vs Iterable connectors
Stream Iterable
Connectors
• File
• FTP
• HTTP
• Sockets
• Database
• SalesForce
All contents © MuleSoft, LLC
LIVE DEMO
All contents © MuleSoft, LLC
Streaming in DataWeave
All contents © MuleSoft, LLC
Could we build a solution
using DW and Non-Repeatable stream...?
All contents © MuleSoft, LLC
Streaming in DataWeave
● DataWeave supports end-to-end streaming through a flow
● Speeds the processing of large documents without overloading memory
● When in deferred mode, DW passes streamed output data directly to next message processor
● The basic unit of the stream is specific to the data format.
○ a record in a CSV document
○ an element of an array in a JSON document
○ a collection in an XML document
● Streaming accesses each unit of the stream sequentially, it doesn't support random access to a
document
● Streaming is not enabled by default
All contents © MuleSoft, LLC
Enabling Streaming in DataWeave
● streaming property, for reading source data as a stream (MIME Type section)
All contents © MuleSoft, LLC
Enabling Streaming in DataWeave
● deferred writer property, for passing an output stream directly to the next message
processor in a flow
All contents © MuleSoft, LLC
Streaming CSV in DataWeave
● Each row below the CSV header is a streamable record
Sample CSV:
name,lastName,age
mariano,achaval,37
leandro,shokida,30
pedro,achaval,4
christian,chibana,25
sara,achaval,2
matias,achaval,8
Sample DW script:
%dw 2.0
output application/json deferred=true
---
payload map (record) ->
{
FullName: record.lastName ++ "," ++
record.name,
Age: record.age
}
All contents © MuleSoft, LLC
Streaming CSV in DataWeave
● Each row below the CSV header is a streamable record
Sample CSV:
name,lastName,age
mariano,achaval,37
leandro,shokida,30
pedro,achaval,4
christian,chibana,25
sara,achaval,2
matias,achaval,8
Sample DW script:
%dw 2.0
output application/json deferred=true
---
[payload[-2], payload[-1], payload[3]]
ERROR HERE
All contents © MuleSoft, LLC
Streaming JSON in DataWeave
● The unit of a JSON stream is each element in an array
Sample JSON:
[
{
"firstName": "John",
"lastName": "Smith",
"age": "37"
},
{
"firstName": "Foo",
"lastName": "Bar",
"age": "30"
}
]
Sample DW script:
%dw 2.0
output application/json deferred=true
---
payload map (record) ->
{
FullName: record.firstName ++ ","
++ record.lastName,
Age: record.age
}
All contents © MuleSoft, LLC
Streaming XML in DataWeave
● XML is more complicated than JSON because
there are no arrays in the document
● To enable XML streaming the property
collectionPath has to be provided
<order>
<header>
<date>Wed Nov 15 13:45:28 EST
2006</date>
<customer
number="1">Joe</customer>
</header>
<order-items>
<order-item id="31">
<product>111</product>
<quantity>2</quantity>
<price>8.90</price>
</order-item>
<order-item id="31">
<product>222</product>
<quantity>7</quantity>
<price>5.20</price>
</order-item>
(...)
</order-items>
</order
All contents © MuleSoft, LLC
Validate a Script using @StreamCapable()
● The @StreamCapable() validator checks a
script against the following criteria:
○ The variable is referenced only once.
○ No index selector is set for negative
access, such as [-1].
○ No reference to the variable is found in a
nested lambda.
● If all criteria are met, the selected data
is streamable
Sample DW script:
%dw 2.0
@StreamCapable()
input payload application/csv
output application/json deferred=true
---
payload map (record) ->
{
// script here...
}
All contents © MuleSoft, LLC
LIVE DEMO
All contents © MuleSoft, LLC
Let's summarize
● Non-Repeatable Streams
○ The input stream is read only once
○ No extra memory or performance overhead in comparison to repeatable streams
● Repeatable In Memory Streams
○ The default for the Mule Kernel (formerly called Mule Runtime Community Edition)
○ Uses a default max buffer size of 500 objects (Iterable) or 1024KB (binary)
○ The buffer is extended from the initial size until the max buffer size is reached
○ If the stream exceeds the max buffer size - the applications fails
● File-Stored Repeatable Stream
○ The default for Mule EE (and only available in Mule EE)
○ By default it store 500 objects (Iterable) or 512KB (binary) in it's memory buffer
○ If the stream exceeds the memory buffer then Kryo serializer writes data to disk
All contents © MuleSoft, LLC
Performance considerations
All contents © MuleSoft, LLC
Performance considerations
● Repeatable streams introduced in Mule 4 are a good compromise between
performance and convenience/robustness. It's not a coincidence that they are set
as defaults ;-)
● More most of the cases (input data relatively small) Repeatable streams should be
used as they hide the complexity of streams
● For large data (gigabytes or more) Non-repeatable streams should be definitely
considered as they provide exceptional good performance and low memory
consumption
● What about Batch Jobs?
● Once you decide Non-Repeatable streams will be used you have to ensure that:
○ The input stream is read only once
○ The input stream is not read simultaneously by multiple threads
○ Transform Message / DataWeave is used properly and supports streaming
All contents © MuleSoft, LLC
Please remember:
Conduct proper
performance testing
before going to PROD!
All contents © MuleSoft, LLC
THANK YOU :)
Quiz & Lottery
Trivia Quiz
● Remember!
○ The quicker you respond more point you earn
○ Only good answers count ☺
○ Only one voucher per winner per month
○ Training account with the given email
● Prize is sponsored by
Three winners of today’s
quiz receives:
Free voucher for MuleSoft
online training
47
Go to www.menti.com and use the code 9155 3697
Congratulation
● Congratulation to all the winners
○ of the Quiz
○ of the lottery
48
Go to www.menti.com and use the code 9155 3697
Wrap up
Share your knowledge
● Become a speaker and share your knowledge with our community
● Submit your idea via this form:
https://tinyurl.com/become-speaker
via email patryk.bandurski@gmail.com
or
50
● Share:
○ Tweet using the hashtag #MuleSoftMeetups
○ Invite your network to join: https://meetups.mulesoft.com/warsaw/
● Feedback:
○ Fill out the survey feedback and suggest topics for upcoming events
○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program
What’s next?
51
See you next time

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

MuleSoft Event Driven Architecture (EDA Patterns in MuleSoft) - VirtualMuleys63
MuleSoft Event Driven Architecture (EDA Patterns in MuleSoft) - VirtualMuleys63MuleSoft Event Driven Architecture (EDA Patterns in MuleSoft) - VirtualMuleys63
MuleSoft Event Driven Architecture (EDA Patterns in MuleSoft) - VirtualMuleys63
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 
What’s Mule 4.3? How Does Anytime RTF Help? Our insights explain.
What’s Mule 4.3? How Does Anytime RTF Help? Our insights explain. What’s Mule 4.3? How Does Anytime RTF Help? Our insights explain.
What’s Mule 4.3? How Does Anytime RTF Help? Our insights explain.
 
MuleSoft Surat Meetup#54 - MuleSoft Automation
MuleSoft Surat Meetup#54 - MuleSoft AutomationMuleSoft Surat Meetup#54 - MuleSoft Automation
MuleSoft Surat Meetup#54 - MuleSoft Automation
 
MuleSoft Online Meetup a Guide to RTF application deployment - October 2020
MuleSoft Online Meetup   a Guide to RTF application deployment  - October 2020MuleSoft Online Meetup   a Guide to RTF application deployment  - October 2020
MuleSoft Online Meetup a Guide to RTF application deployment - October 2020
 
MuleSoft Architecture Presentation
MuleSoft Architecture PresentationMuleSoft Architecture Presentation
MuleSoft Architecture Presentation
 
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
 
Error Handling in Mulesoft
Error Handling in MulesoftError Handling in Mulesoft
Error Handling in Mulesoft
 
Virtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment modelVirtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment model
 
Cloudhub 2.0
Cloudhub 2.0Cloudhub 2.0
Cloudhub 2.0
 
MuleSoft JWT Demystified
MuleSoft JWT DemystifiedMuleSoft JWT Demystified
MuleSoft JWT Demystified
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 
VPCs, Metrics Framework, Back pressure : MuleSoft Virtual Muleys Meetups
VPCs, Metrics Framework, Back pressure  : MuleSoft Virtual Muleys MeetupsVPCs, Metrics Framework, Back pressure  : MuleSoft Virtual Muleys Meetups
VPCs, Metrics Framework, Back pressure : MuleSoft Virtual Muleys Meetups
 
Running and Managing Mule Applications
Running and Managing Mule ApplicationsRunning and Managing Mule Applications
Running and Managing Mule Applications
 
Mulesoft meetup slides mumbai_20113019_exception_handling
Mulesoft meetup slides mumbai_20113019_exception_handlingMulesoft meetup slides mumbai_20113019_exception_handling
Mulesoft meetup slides mumbai_20113019_exception_handling
 
Best Practices for API Security
Best Practices for API SecurityBest Practices for API Security
Best Practices for API Security
 
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 
Custom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker exampleCustom policies in mule 4 and a circuit breaker example
Custom policies in mule 4 and a circuit breaker example
 
MuleSoft Composer for Salesforce.pptx
MuleSoft Composer for Salesforce.pptxMuleSoft Composer for Salesforce.pptx
MuleSoft Composer for Salesforce.pptx
 

Semelhante a Warsaw MuleSoft Meetup #12 Effective Streaming

Semelhante a Warsaw MuleSoft Meetup #12 Effective Streaming (20)

Mulesoft Meetup Milano #9 - Batch Processing and CI/CD
Mulesoft Meetup Milano #9 - Batch Processing and CI/CDMulesoft Meetup Milano #9 - Batch Processing and CI/CD
Mulesoft Meetup Milano #9 - Batch Processing and CI/CD
 
Warsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft ODataWarsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft OData
 
Streaming in Mule
Streaming in MuleStreaming in Mule
Streaming in Mule
 
Unleash MuleSoft Platform for Enterprise Healthcare Solutions
Unleash MuleSoft Platform for Enterprise Healthcare SolutionsUnleash MuleSoft Platform for Enterprise Healthcare Solutions
Unleash MuleSoft Platform for Enterprise Healthcare Solutions
 
Denver MuleSoft Meetup: Greatest MuleSoft Hits of 2022
Denver MuleSoft Meetup: Greatest MuleSoft Hits of 2022Denver MuleSoft Meetup: Greatest MuleSoft Hits of 2022
Denver MuleSoft Meetup: Greatest MuleSoft Hits of 2022
 
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
 
20210916 mule soft_meetup_nz_online_uploadedversion
20210916 mule soft_meetup_nz_online_uploadedversion20210916 mule soft_meetup_nz_online_uploadedversion
20210916 mule soft_meetup_nz_online_uploadedversion
 
Machine learning and big data @ uber a tale of two systems
Machine learning and big data @ uber a tale of two systemsMachine learning and big data @ uber a tale of two systems
Machine learning and big data @ uber a tale of two systems
 
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalertsAhmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
 
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalertsAhmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
 
Cracow MuleSoft Meetup #1
Cracow MuleSoft Meetup #1Cracow MuleSoft Meetup #1
Cracow MuleSoft Meetup #1
 
Apache Flume - DataDayTexas
Apache Flume - DataDayTexasApache Flume - DataDayTexas
Apache Flume - DataDayTexas
 
MuleSoft Manchester Meetup #2 slides 29th October 2019
MuleSoft Manchester Meetup #2 slides 29th October 2019MuleSoft Manchester Meetup #2 slides 29th October 2019
MuleSoft Manchester Meetup #2 slides 29th October 2019
 
Warsaw MuleSoft Meetup #13.pptx
Warsaw MuleSoft Meetup #13.pptxWarsaw MuleSoft Meetup #13.pptx
Warsaw MuleSoft Meetup #13.pptx
 
Bootstrapping state in Apache Flink
Bootstrapping state in Apache FlinkBootstrapping state in Apache Flink
Bootstrapping state in Apache Flink
 
#OSSPARIS19 - How to improve database observability - CHARLES JUDITH, Criteo
#OSSPARIS19 - How to improve database observability - CHARLES JUDITH, Criteo#OSSPARIS19 - How to improve database observability - CHARLES JUDITH, Criteo
#OSSPARIS19 - How to improve database observability - CHARLES JUDITH, Criteo
 
Princeton-NJ-Meetup-MuleSoft SumoLogic Integration.pptx
Princeton-NJ-Meetup-MuleSoft SumoLogic Integration.pptxPrinceton-NJ-Meetup-MuleSoft SumoLogic Integration.pptx
Princeton-NJ-Meetup-MuleSoft SumoLogic Integration.pptx
 
Sea of Data
Sea of DataSea of Data
Sea of Data
 
University of Delaware - Improving Web Protocols (early SPDY talk)
University of Delaware - Improving Web Protocols (early SPDY talk)University of Delaware - Improving Web Protocols (early SPDY talk)
University of Delaware - Improving Web Protocols (early SPDY talk)
 
Embarking on MuleSoft Automation Journey via RPA, Composer and Flex Gateway
Embarking on MuleSoft Automation Journey via RPA, Composer and Flex GatewayEmbarking on MuleSoft Automation Journey via RPA, Composer and Flex Gateway
Embarking on MuleSoft Automation Journey via RPA, Composer and Flex Gateway
 

Mais de Patryk Bandurski

Mais de Patryk Bandurski (13)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Warsaw MuleSoft Meetup #16 DF Tour.pptx
Warsaw MuleSoft Meetup #16 DF Tour.pptxWarsaw MuleSoft Meetup #16 DF Tour.pptx
Warsaw MuleSoft Meetup #16 DF Tour.pptx
 
Warsaw MuleSoft Meetup #15 - Hyperautomation with MuleSoft - Composer 101
Warsaw MuleSoft Meetup #15 - Hyperautomation with MuleSoft - Composer 101Warsaw MuleSoft Meetup #15 - Hyperautomation with MuleSoft - Composer 101
Warsaw MuleSoft Meetup #15 - Hyperautomation with MuleSoft - Composer 101
 
Marketing Cloud integration with MuleSoft
Marketing Cloud integration with MuleSoftMarketing Cloud integration with MuleSoft
Marketing Cloud integration with MuleSoft
 
MuleSoft CloudHub API Versioning
MuleSoft CloudHub API VersioningMuleSoft CloudHub API Versioning
MuleSoft CloudHub API Versioning
 
Warsaw mulesoft meetup #9 mastering integration with salesforce
Warsaw mulesoft meetup #9 mastering integration with salesforceWarsaw mulesoft meetup #9 mastering integration with salesforce
Warsaw mulesoft meetup #9 mastering integration with salesforce
 
Warsaw MuleSoft Meetup #7 - custom policy
Warsaw MuleSoft Meetup #7 - custom policyWarsaw MuleSoft Meetup #7 - custom policy
Warsaw MuleSoft Meetup #7 - custom policy
 
Warsaw MuleSoft Meetup #6 - CI/CD
Warsaw MuleSoft Meetup  #6 - CI/CDWarsaw MuleSoft Meetup  #6 - CI/CD
Warsaw MuleSoft Meetup #6 - CI/CD
 
Mule soft meetup warsaw november 13th, 2019
Mule soft meetup   warsaw november 13th, 2019Mule soft meetup   warsaw november 13th, 2019
Mule soft meetup warsaw november 13th, 2019
 
MuleSoft approach to the integration - Warsaw MuleSoft Meetup
MuleSoft approach to the integration - Warsaw MuleSoft MeetupMuleSoft approach to the integration - Warsaw MuleSoft Meetup
MuleSoft approach to the integration - Warsaw MuleSoft Meetup
 
Warsaw MuleSoft Meetup - Runtime Fabric
Warsaw MuleSoft Meetup - Runtime FabricWarsaw MuleSoft Meetup - Runtime Fabric
Warsaw MuleSoft Meetup - Runtime Fabric
 
MuleSoft Meetup Warsaw Group DataWeave 2.0
MuleSoft Meetup Warsaw Group DataWeave 2.0MuleSoft Meetup Warsaw Group DataWeave 2.0
MuleSoft Meetup Warsaw Group DataWeave 2.0
 
MuleSoft Meetup Warsaw Group #1
MuleSoft  Meetup Warsaw Group #1MuleSoft  Meetup Warsaw Group #1
MuleSoft Meetup Warsaw Group #1
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Warsaw MuleSoft Meetup #12 Effective Streaming

  • 1. 31/03/2022 Warsaw MuleSoft Meetup Group Effective Streaming in Mule 4
  • 2. ● Introductions & Community Updates ● Effective Streaming in Mule 4 ● Quiz & Lottery Agenda 2
  • 5. ● IT Expert at Roche ● More than 21 years of experience in IT ● MuleSoft Certifications: MCIA, MCPA, MCD ● Salesforce Certifications: Administrator, Platform App Builder, Platform Developer I ● I like technology :) https://www.linkedin.com/in/jacekbialecki/ 5 Jacek Białecki Speaker
  • 6. ● Subject Matter Expert at PwC Poland ● MuleSoft Ambassador ● MuleSoft Meetup Leader for Warsaw, Poland ● Working with MuleSoft products for over 10 years now ● One of Salesforce Trailblazers https://trailhead.salesforce.com/trailblazers/patryk-bandurski Organizer Check out my integration blog https://ambassadorpatryk.com/blog 6
  • 7. Share the event ● Share the Meetup in your social media ● Tag the event using #MuleSoftMeetup #WarsawMuleSoftMeetup Thanks ☺ 7
  • 8. Lottery ● How it works? ○ During the event randomly is selected a winner among the present attendees. ○ One winner at a time! ○ Three winners at the event ○ I will ask winners to send me Direct Message with email address ● Prize is sponsored by Three winners of today’s lottery receives: Amazon Voucher for 30$ 8 Go to www.menti.com and use the code 9155 3697
  • 11. MuleSoft Meetups Upcoming MuleSoft Meetups Follwow Mariana Lemus profile on Linkedin Follow MuleSoft Community group on Linkedin 11
  • 12. All contents © MuleSoft, LLC Effective Streaming in Mule 4
  • 13. All contents © MuleSoft, LLC Agenda ● Introduction to Streams ● Streams in Mule 4 ● DEMO ● Streaming in DataWeave ● DEMO ● Summary & performance considerations
  • 14. All contents © MuleSoft, LLC Introduction to Streams
  • 15. All contents © MuleSoft, LLC Concept of Streams Scenario - read whole input to the memory
  • 16. All contents © MuleSoft, LLC Concept of Streams Scenario - read whole input to the memory Problem: MEMORY CONSUMPTION Out Of Memory
  • 17. All contents © MuleSoft, LLC Concept of Streams Scenario – splitting files
  • 18. All contents © MuleSoft, LLC Concept of Streams Scenario - pagination https://api.com/items?offset=200&limit=100
  • 19. All contents © MuleSoft, LLC Concept of Streams Scenario - read data as a stream
  • 20. All contents © MuleSoft, LLC This is (also) a stream :)
  • 21. All contents © MuleSoft, LLC Streams in Mule 4
  • 22. All contents © MuleSoft, LLC Streams in MuleSoft 4: ● Non-Repeatable Streams (available in Mule 3) ● In-Memory Repeatable Stream (new in Mule 4) ● File-Stored Repeatable Stream (new in Mule 4)
  • 23. All contents © MuleSoft, LLC Streams in MuleSoft 4: Non-Repeatable Streams ● Cannot be read more than once ● Cannot be consumed simultaneously ● Very performant but needs careful treatment ○ No additional memory buffers ○ No I/O operations (disk based buffers) ● Suitable for processing LARGE streams
  • 24. All contents © MuleSoft, LLC Streams in MuleSoft 4: Non-repeatable Streams ● Cannot be read more than once (examples)
  • 25. All contents © MuleSoft, LLC Streams in MuleSoft 4: Non-repeatable Streams ● Cannot be consumed simultaneously (example)
  • 26. All contents © MuleSoft, LLC New in Mule 4: In-Memory Repeatable Stream
  • 27. All contents © MuleSoft, LLC New in Mule 4: File-Stored Repeatable Stream Uses KRYO serializer. Better than standard Java serializer but still cannot serialize everything A typical case is a POJO containing an org.apache.xerces.jaxp.datatype.XMLGregorianCale ndarImpl, which is in use in the NetSuite or Microsoft Dynamics CRM connectors. Only available in Mule Enterprise Edition (Mule EE)
  • 28. All contents © MuleSoft, LLC Stream vs Iterable connectors Stream Iterable Connectors • File • FTP • HTTP • Sockets • Database • SalesForce
  • 29. All contents © MuleSoft, LLC LIVE DEMO
  • 30. All contents © MuleSoft, LLC Streaming in DataWeave
  • 31. All contents © MuleSoft, LLC Could we build a solution using DW and Non-Repeatable stream...?
  • 32. All contents © MuleSoft, LLC Streaming in DataWeave ● DataWeave supports end-to-end streaming through a flow ● Speeds the processing of large documents without overloading memory ● When in deferred mode, DW passes streamed output data directly to next message processor ● The basic unit of the stream is specific to the data format. ○ a record in a CSV document ○ an element of an array in a JSON document ○ a collection in an XML document ● Streaming accesses each unit of the stream sequentially, it doesn't support random access to a document ● Streaming is not enabled by default
  • 33. All contents © MuleSoft, LLC Enabling Streaming in DataWeave ● streaming property, for reading source data as a stream (MIME Type section)
  • 34. All contents © MuleSoft, LLC Enabling Streaming in DataWeave ● deferred writer property, for passing an output stream directly to the next message processor in a flow
  • 35. All contents © MuleSoft, LLC Streaming CSV in DataWeave ● Each row below the CSV header is a streamable record Sample CSV: name,lastName,age mariano,achaval,37 leandro,shokida,30 pedro,achaval,4 christian,chibana,25 sara,achaval,2 matias,achaval,8 Sample DW script: %dw 2.0 output application/json deferred=true --- payload map (record) -> { FullName: record.lastName ++ "," ++ record.name, Age: record.age }
  • 36. All contents © MuleSoft, LLC Streaming CSV in DataWeave ● Each row below the CSV header is a streamable record Sample CSV: name,lastName,age mariano,achaval,37 leandro,shokida,30 pedro,achaval,4 christian,chibana,25 sara,achaval,2 matias,achaval,8 Sample DW script: %dw 2.0 output application/json deferred=true --- [payload[-2], payload[-1], payload[3]] ERROR HERE
  • 37. All contents © MuleSoft, LLC Streaming JSON in DataWeave ● The unit of a JSON stream is each element in an array Sample JSON: [ { "firstName": "John", "lastName": "Smith", "age": "37" }, { "firstName": "Foo", "lastName": "Bar", "age": "30" } ] Sample DW script: %dw 2.0 output application/json deferred=true --- payload map (record) -> { FullName: record.firstName ++ "," ++ record.lastName, Age: record.age }
  • 38. All contents © MuleSoft, LLC Streaming XML in DataWeave ● XML is more complicated than JSON because there are no arrays in the document ● To enable XML streaming the property collectionPath has to be provided <order> <header> <date>Wed Nov 15 13:45:28 EST 2006</date> <customer number="1">Joe</customer> </header> <order-items> <order-item id="31"> <product>111</product> <quantity>2</quantity> <price>8.90</price> </order-item> <order-item id="31"> <product>222</product> <quantity>7</quantity> <price>5.20</price> </order-item> (...) </order-items> </order
  • 39. All contents © MuleSoft, LLC Validate a Script using @StreamCapable() ● The @StreamCapable() validator checks a script against the following criteria: ○ The variable is referenced only once. ○ No index selector is set for negative access, such as [-1]. ○ No reference to the variable is found in a nested lambda. ● If all criteria are met, the selected data is streamable Sample DW script: %dw 2.0 @StreamCapable() input payload application/csv output application/json deferred=true --- payload map (record) -> { // script here... }
  • 40. All contents © MuleSoft, LLC LIVE DEMO
  • 41. All contents © MuleSoft, LLC Let's summarize ● Non-Repeatable Streams ○ The input stream is read only once ○ No extra memory or performance overhead in comparison to repeatable streams ● Repeatable In Memory Streams ○ The default for the Mule Kernel (formerly called Mule Runtime Community Edition) ○ Uses a default max buffer size of 500 objects (Iterable) or 1024KB (binary) ○ The buffer is extended from the initial size until the max buffer size is reached ○ If the stream exceeds the max buffer size - the applications fails ● File-Stored Repeatable Stream ○ The default for Mule EE (and only available in Mule EE) ○ By default it store 500 objects (Iterable) or 512KB (binary) in it's memory buffer ○ If the stream exceeds the memory buffer then Kryo serializer writes data to disk
  • 42. All contents © MuleSoft, LLC Performance considerations
  • 43. All contents © MuleSoft, LLC Performance considerations ● Repeatable streams introduced in Mule 4 are a good compromise between performance and convenience/robustness. It's not a coincidence that they are set as defaults ;-) ● More most of the cases (input data relatively small) Repeatable streams should be used as they hide the complexity of streams ● For large data (gigabytes or more) Non-repeatable streams should be definitely considered as they provide exceptional good performance and low memory consumption ● What about Batch Jobs? ● Once you decide Non-Repeatable streams will be used you have to ensure that: ○ The input stream is read only once ○ The input stream is not read simultaneously by multiple threads ○ Transform Message / DataWeave is used properly and supports streaming
  • 44. All contents © MuleSoft, LLC Please remember: Conduct proper performance testing before going to PROD!
  • 45. All contents © MuleSoft, LLC THANK YOU :)
  • 47. Trivia Quiz ● Remember! ○ The quicker you respond more point you earn ○ Only good answers count ☺ ○ Only one voucher per winner per month ○ Training account with the given email ● Prize is sponsored by Three winners of today’s quiz receives: Free voucher for MuleSoft online training 47 Go to www.menti.com and use the code 9155 3697
  • 48. Congratulation ● Congratulation to all the winners ○ of the Quiz ○ of the lottery 48 Go to www.menti.com and use the code 9155 3697
  • 50. Share your knowledge ● Become a speaker and share your knowledge with our community ● Submit your idea via this form: https://tinyurl.com/become-speaker via email patryk.bandurski@gmail.com or 50
  • 51. ● Share: ○ Tweet using the hashtag #MuleSoftMeetups ○ Invite your network to join: https://meetups.mulesoft.com/warsaw/ ● Feedback: ○ Fill out the survey feedback and suggest topics for upcoming events ○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program What’s next? 51
  • 52. See you next time