MCDLevel1Fundamentals Flashcards

(53 cards)

1
Q

how do you define function in dw 2, whats keyword?

A

TODO: there are more ways here https://docs.mulesoft.com/dataweave/2.3/dataweave-functions

its "fun" like in
fun myFunction(param1, param2, ...) =
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.@ } ] }

A

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”
}
}
]
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

type of queues in Anypoint MQ?j

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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} }

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A

${https.port}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

when calling endpoint like this, how is dw looking query params up? e.g. http://localhost:8081/retrieveQueryParams?Name=John&EmpId=123

A

%dw 2.0
output application/json

{
“Name”:attributes.queryParams.Name,
“EmployeeId”:attributes.queryParams.EmpId
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

when calling endpoint and using uri params, how are they looked up then?

A

[attributes.uriParams.name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how is mule 3 #[flowVars.varName] replaced in mule 4?

A

[vars.varName]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how is mule 3 #[message.inboundProperties.’http.version’] replaced in mule 4?

A

…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’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

trait name for specifying client id in raml?

A

client-id-required
https://docs.mulesoft.com/api-manager/2.x/prepare-raml-task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

hur placerar man query parametrar, vad heter den och vilka attribut har de?

A

/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:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

is this removing one array from another or removing elements of the array element?

%dw 2.0
output application/json

([0, 1] – [0, 2])

A

//Elements due to minus minus. Result is single element in the first array

[
1
]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what comes first in a filter operation, index or value?

A

[9,2,3,4,5] filter (value, index) -> (value > 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how can you access header, and it doesnt look like attributes.uriParams.X or attributes.queryParams.X or similar?

A

attributes.header[‘user-agent’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what does #[payload.*name] and #[payload..name] have in common? and the difference?

A

common: both return Array with values of key:value pairs
difference: the .* is multi value selector while .. is Descendants selector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does this Multivalue selector return?

%dw 2.0
output application/json

payload.users.*user

and given input:

A

Multi value selector can either be applied over an :object or an :array.

[“Mariano”, “Martin”, “Leandro”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what does this produce
contains(“names”, “name”)
“nameing” contains “name”

A

true,
true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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} }

A

{ “0”: { “b”: “a” }, “1”: { “d”: “c” } }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

what to do when backpressure error arises?

A

https://help.mulesoft.com/s/article/Dealing-with-MULE-FLOW-BACK-PRESSURE-error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what does zip operator do in dataweave?

A

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”] ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

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

23
Q

semantic versioning?

A

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

24
Q

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?

A

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”
}
}
}

25
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"} }
26
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
27
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)
28
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
29
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
30
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!!!
31
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
32
what is attribute selector?
and to select it payload.user.@name See https://docs.mulesoft.com/dataweave/2.2/dataweave-selectors
33
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" ]
34
check out do syntax with --- in the middle of delclaration, whats allowed in terms of scoping, imports etc
?
35
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" ]
36
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
37
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
38
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
39
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
40
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). ```
41
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 : { ..
42
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
43
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.
44
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
45
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
46
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
47
What payload is returned by a Database SELECT operation that does not match any rows in database?
Empty array
48
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
49
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
50
What is the default port used by Mule application debugger configuration in Anypoint Studio?
6666
51
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
52
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 ] ]
53
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?