MCDLevel1Fundamentals Flashcards
how do you define function in dw 2, whats keyword?
TODO: there are more ways here https://docs.mulesoft.com/dataweave/2.3/dataweave-functions
its "fun" like in fun myFunction(param1, param2, ...) =
whats @ used for in dw? and how does it work given. Consider
%dw 2.0 var myVar = read(‘
SomeBrand ‘,
‘application/xml’)
output application/json
{ item: [ { “type” : myVar.product.@.”type”,
“name” : myVar.product.brand,
“attributes”: myVar.product.@ } ] }

XML Attribute Selector (.@myKey)
@, .@keyName
String value of the selected attribute’. Pay attention when something comes after @ vs nothing. .@ take all attributes and represent it as object and not array.
{
“item”: [
{
“type”: “electronic”,
“name”: “SomeBrand”,
“attributes”: {
“id”: “1”,
“type”: “electronic”
}
}
]
}
type of queues in Anypoint MQ?j
1) Standard queue
These queues don’t guarantee a specific message order. Standard queues are the best fit for applications in which messages must be delivered quickly.
Anypoint MQ supports up to 120,000 in-flight messages per standard queue.
2) FIFO (first in, first out) queue
These queues ensure that your messages arrive in order. FIFO queues are the best fit for applications requiring strict message ordering and exactly-once delivery, but in which message delivery speed is of less importance. See FIFO Queues.
Anypoint MQ supports 10 in-flight messages per message group in a FIFO queue. Anypoint MQ doesn’t limit the number of message groups in a FIFO queue.
1) What DataWeave 2.0 type can be used as input to a mapObject operation? 2) Whats output given
%dw 2.0
output application/json
—
{“a”:”b”,”c”:”d”} mapObject (value,key,index) -> { (index) : { (value):key} }
1) Object (not map or array or anything)
2) { “0”: { “b”: “a” }, “1”: { “d”: “c” } }
Obs! pay attention to the order of value, key, index
as it can be shuffled on the exam. Remember it as V.K.I , sounds almost like BMI.
what reserved property can be defined and used in a mule application to allow an https listener be accessed by external clients after its deployed to cloudhub?
${https.port}
when calling endpoint like this, how is dw looking query params up? e.g. http://localhost:8081/retrieveQueryParams?Name=John&EmpId=123
%dw 2.0
output application/json
—
{
“Name”:attributes.queryParams.Name,
“EmployeeId”:attributes.queryParams.EmpId
}
when calling endpoint and using uri params, how are they looked up then?
[attributes.uriParams.name]
how is mule 3 #[flowVars.varName] replaced in mule 4?
[vars.varName]
how is mule 3 #[message.inboundProperties.’http.version’] replaced in mule 4?
…in a Transform message:
if (attributes.headers[‘keyname’] != null and attributes.headers[‘keyname’] != “”) attributes.headers[‘keyname’] as String else null
or directly use this in a log:
attributes.headers[‘keyname’]
trait name for specifying client id in raml?
client-id-required
https://docs.mulesoft.com/api-manager/2.x/prepare-raml-task
hur placerar man query parametrar, vad heter den och vilka attribut har de?
/books:
/{bookTitle}
get:
queryParameters:
author:
displayName: Author
type: string
description: An author’s full name
example: Mary Roach
required: false
publicationYear:
displayName: Pub Year
type: number
description: The year released for the first time in the US
example: 1984
required: false
put:
queryParameters:
access_token:
displayName:
is this removing one array from another or removing elements of the array element?
%dw 2.0
output application/json
—
([0, 1] – [0, 2])
//Elements due to minus minus. Result is single element in the first array
[
1
]
what comes first in a filter operation, index or value?
[9,2,3,4,5] filter (value, index) -> (value > 2)
how can you access header, and it doesnt look like attributes.uriParams.X or attributes.queryParams.X or similar?
attributes.header[‘user-agent’]
what does #[payload.*name] and #[payload..name] have in common? and the difference?
common: both return Array with values of key:value pairs
difference: the .* is multi value selector while .. is Descendants selector
What does this Descendants selector return?
%dw 2.0
output application/xml
ns html http://www.w3.org/TR/html4/
ns furniture https://www.w3schools.com/furniture
—
root: {
b: payload.root.furniture#table..name
}
given: TODO: fix pic
just like Single level Explicit Selector, or the Indexed Selector, the Descendants Selector returns the value of the key:value pair that matches the expression.

What does this Multivalue selector return?
%dw 2.0
output application/json
—
payload.users.*user
and given input:

Multi value selector can either be applied over an :object or an :array.
[“Mariano”, “Martin”, “Leandro”]

what does this produce
contains(“names”, “name”)
“nameing” contains “name”
true,
true
mapObject, whats the output?
pay attention its not an array
%dw 2.0
output application/json
—
{“a”:”b” , “c”:”d”} mapObject (value,key,index) -> { (index) : { (value):key} }
{ “0”: { “b”: “a” }, “1”: { “d”: “c” } }
what to do when backpressure error arises?
https://help.mulesoft.com/s/article/Dealing-with-MULE-FLOW-BACK-PRESSURE-error
what does zip operator do in dataweave?
Merges elements from two arrays into an array of arrays.
%dw 2.0
output application/json
—
[0,1] zip [“a”,”b”]
result in
[[0,”a”], [1,”b”] ]
What is the value of the stepVar variable after the processing of records in a Batch Job? P.s. read the chapter about batch jobs
null
semantic versioning?
https://docs.mulesoft.com/exchange/to-change-raml-version
Major versions = first digit in 1.2.3
When introducing a change in the structure of the API that requires the user of the API to adapt the interface on the consumer side, such as a new required operation argument
Minor versions
When introducing a backward compatible change to the API that does not require an API user to change, such as a new optional element
Patch versions
When introducing a backward compatible bug fix or documentation update
Scatter-Gather sends the event to each route concurrently and returns a collection of all results. What is the final output of the Scatter-Gather?
e.g. like this:
{
“0”: {
“inboundAttachmentNames”: [],
“exceptionPayload”: null,
“inboundPropertyNames”: [],
“outboundAttachmentNames”: [],
“payload”: “”,
“outboundPropertyNames”: [],
“attributes”: {
“headers”: {
“user-agent”: “PostmanRuntime/7.22.0”,
“accept”: “*/*”,
“cache-control”: “no-cache”,
“postman-token”: “47e20bb3-3726-4437-8b86-8ef55cd27d71”,
“host”: “localhost:8081”,
“accept-encoding”: “gzip, deflate, br”,
“connection”: “keep-alive”
},
“clientCertificate”: null,
“method”: “GET”
}
},
“1”: {
“inboundAttachmentNames”: [],
“exceptionPayload”: null,
“inboundPropertyNames”: [],
“outboundAttachmentNames”: [],
“payload”: “”,
“outboundPropertyNames”: [],
“attributes”: {
“headers”: {
“user-agent”: “PostmanRuntime/7.22.0”,
“accept”: “*/*”,
“cache-control”: “no-cache”,
“postman-token”: “47e20bb3-3726-4437-8b86-8ef55cd27d71”,
“host”: “localhost:8081”,
“accept-encoding”: “gzip, deflate, br”,
“connection”: “keep-alive”
},
“clientCertificate”: null,
“method”: “GET”
}
}
}
how do you format currency String in dataweave and what parenthesis type do you use for formatting?
payload map {
‘price’ : $.price as String {format: “£#,###.00”}
}
Provided this is json input:
[
{ “symbol”: “Krona” }
]
and below is transformation, what is the outcome exactly and why?
%dw 2.0
output application/json
—
payload map {
‘code’ : lower($.symbol)
}
[
{
“code”: “krona”
}
]
because
1) The map function transforms data
2) It iterates over the elements in an array
3) It applies a transformation to each element
4) Applies only to array input
and most importan!!! : It can only output an array
Do we need to import functions that reside in dw::core?
e.g.
%dw 2.0
import dw::core::Strings
fun capitalizeKey(value:String) = Strings::capitalize(value) ++ “Key”
—
payload mapObject ((value, key) ->
{
(capitalizeKey(key as String)) : value
}
)
yes we do, otherwise we get
Unable to resolve reference of: Strings::capitalize
.
7| fun capitalizeKey(value:String) = Strings::capitalize(value) ++ “Key”
^^^^^^^^^^^^^^^^^^^
Location:
main (line: 7, column:35)
if i have a dataweave function in src/main/resources/modules/MyModule.dwl then how do i import in in my dataweave?
import modules::MyModule
See https://developer.mulesoft.com/learn/dataweave/ for details. P.s. it seems we just add another ::nextLevel if nextLevel was a catalogue under modules containing MyModules.dwl instead
can you import variable and function from you dw script? can you alias those?
yes, given custom module:
%dw 2.0
fun myFunc(name:String) = name ++ “_”
var myVar = “Test”
i would import and alias and use it like this
%dw 2.0
import myFunc as appendDash, myVar as weaveName from modules::MyModule
var myVar = “Mapping”
output application/json
—
appendDash(“dataweave”) ++ weaveName ++ “_” ++ myVar
when you see a validate element in the flow, like “validation:is-blank-string”, will it throw exception if is a not empty?
yes, here is curl followed by the result
curl -id “test” http://localhost:8081/sp
HTTP/1.1 500 Server Error
Content-Type: text/plain; charset=UTF-8
Content-Length: 29
Date: Wed, 17 Nov 2021 21:15:34 GMT
Connection: close
whatever validate message!!!
name 3 things you use Api manager for except the usual:
- Create and deploy API proxies.
- Define SLA tiers and apply runtime policies
– Approve, reject, or revoke access to APIs by clients
– Promote managed APIs between environments
– Review API analytics
what is attribute selector?
and to select it
payload.user.@name
See https://docs.mulesoft.com/dataweave/2.2/dataweave-selectors
what does it mean to select EACH, i mean EACH descendant for this and whats the expression? how many childs will it be?
Weave
BAT
BDD
it should be 4 nodes and 3 single strins
%dw 2.0
output application/json
—
payload..
and output is
[
{
“user”: {
“name”: “Weave”,
“user”: {
“name”: “BAT”,
“user”: {
“name”: “BDD”
}
}
}
},
{
“name”: “Weave”,
“user”: {
“name”: “BAT”,
“user”: {
“name”: “BDD”
}
}
},
“Weave”,
{
“name”: “BAT”,
“user”: {
“name”: “BDD”
}
},
“BAT”,
{
“name”: “BDD”
},
“BDD”
]
check out do syntax with — in the middle of delclaration, whats allowed in terms of scoping, imports etc
?
whats another special thing about .. operator?
The DataWeave script uses .. to select the values of all FIRST, not any but FIRST, name elements from the input payload and output those values into a JSON array. E.g.
payload..name for
Weave
BAT
Munit
BDD
gives
[
“Weave”,
“BAT”,
“BDD”
]
does single quotes work as good as doublequotes in dataweae? e.g.
payload.root.h#’$(payload.root.@ref)’
vs
payload.root.h#”$(payload.root.@ref)”
yes, they do
what is this selector called and what does it produce?
Given
Mariano
Martin
Leandro
Admin
org_owner
and dataweave:
%dw 2.0
output application/xml
—
{
users: payload.users.&user
}
its called Key-Value Pair Selector (.&myKey)
Mariano
Martin
Leandro
whats the difference between Custom Dataweave “Mapping File” and “Mapping Module”
Mapping file looks like normal mapping stored in a separate file. Given your mapping file look like:
%dw 2.0
import dw::core::Strings
fun capitalizeKey(value:String) = Strings::capitalize(value) ++ “Key”
—
payload mapObject ((value, key) ->
{
(capitalizeKey(key as String)) : value
}
)
then you can use it like these:
%dw 2.0
import modules::MyMapping
output application/json
—
MyMapping::main(payload: { “user” : “bar” })
See https://docs.mulesoft.com/dataweave/2.4/dataweave-create-module
how can dw “mapping module” look like ?
e.g. :
%dw 2.0
fun myFunc(myInput: String) = myInput ++ “_”
var name = “MyData”
ns mynamespace http://acme.com/bar
see See https://docs.mulesoft.com/dataweave/2.4/dataweave-create-module
what are the several ways to import mapping module?
1) Import the module, for example: import modules::MyModule. In this case, you must include the name of the module when you call the element (here, a function) in it, for example: MyModule::myFunc.
2) Import all elements from the module, for example: import \* from modules::MyModule. In this case, you do not need to include the name of the module when you call the element. For example: myFunc("dataweave") ++ "name" works.
3) Import specific elements from a module, for example: import myFunc from modules::MyModule. In this case, you do not need to include the name of the module when you call the element. For example: myFunc("dataweave") ++ "name" works. You can import multiple elements from the module like this, for example: import myFunc someOtherFunction from modules::MyModule (assuming both myFunc and someOtherFunction are defined in the module).
when you want to have map operation as a node value like trains: ….something map operation here …
what are the parentheses you use?
When mapping array elements (JSON or JAVA) to XML, wrap the map operations in {(..)} e.g.
trains: {( alexMap map ((something, index) -> train : { ..
whats important to remember about scope of foreach?
changes made to payload in for each loop are not available outside for each scope. delcaring/incrementing variable is fine though
For each method of the RAML specification , what does the REST connect module provide?
For each method of the RAML specification , REST connect module provide an OPERATION, not a flow. Think how it looks in the palette! And dont forget The Exchange backend uses REST Connect to transparently convert a REST API specification to a Mule 3 and Mule 4 connector.
A Scatter-Gather processes three separate HTTP requests. Each request returns a Mule event with a JSON payload. What is the final output of the Scatter-Gather?
An object containing Mule event objects, not payload, not messages, but event objects
An SLA based policy has been enabled in API Manager. What is the next step to configure API proxy to enforce new SLA policy?
Add required headers to RAML specification and redeploy new API proxy
By default , what happens to a file after it is read using an FTP connector Read operation
The file stays in the same folder unchanged
What payload is returned by a Database SELECT operation that does not match any rows in database?
Empty array
Is this a working declaration: ?
%dw 2.0
output application/json
fun createUserData(name, countryCode : String = “US”) = { “User name” : name, “Location”: countryCode}
—
[createUserData(“Cristian”, “AR”), createUserData(“Max The Mule”)]
yes
Which one will be called?
%dw 2.0
output application/json
fun toUpper(a: String) = upper(a)
fun toUpper(a: Any) = null
—
toUpper(“hi!”)
the first one
What is the default port used by Mule application debugger configuration in Anypoint Studio?
6666
Does syntax with wildcard like /mypath/* work both in http listener and http listener configurations?
No, Please note wildcards wont work in HTTP Listener configurations. They will work only when you configure path in HTTP Listener
what is the result of this?
%dw 2.0
output application/json
—
([0, 1] + [0, 2])
//second array injected inside like if its an element
[
0,
1,
[
0,
2
]
]
Result 20231201: pass., 4-5 out of max 8 questions failed. questions i wondered:
1)batch steps does not modify payload right. what are those stats in the end then when printing payload. stepsvar in the end?
2) does calling another non-private flow follow same rules like calling private flow? when it comes to err handling, attribs, etc?