Version 23.1 by Erik Bakker on 2024/06/21 14:47

Hide last authors
Erik Bakker 6.1 1 {{container}}{{container layoutStyle="columns"}}(((
Erik Bakker 23.1 2 In a previous [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level. File based connectivity.intermediate-file-based-connectivity-smb-connectivity.WebHome||target="blank"]] on this subject, we discussed how to configure the various variants of SMB connectivity. We already mentioned that more dynamic options, such as automatically creating a "multi-level" directory (i.e.,/root/sub), are complex to configure and require a different approach.
Erik Bakker 21.1 3
Erik Bakker 23.1 4 In this microlearning, we will examine how to manipulate all settings on the SMB Session Factory to create dynamic values that are injected into the component when a message is processed by the flow.
eMagiz 1.1 5
Erik Bakker 23.1 6 If you have any questions, don't hesitate to contact [[academy@emagiz.com>>mailto:academy@emagiz.com]].
eMagiz 1.1 7
8 == 1. Prerequisites ==
9
10 * Advanced knowledge of the eMagiz platform
11
12 == 2. Key concepts ==
13
Erik Bakker 22.1 14 This microlearning centers around dynamically manipulating settings on the SMB Session Factory.
eMagiz 1.1 15
Erik Bakker 23.1 16 * This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares.
eMagiz 1.1 17
Erik Bakker 22.1 18 == 3. Dynamically manipulate SMB Session Settings ==
eMagiz 1.1 19
Erik Bakker 23.1 20 In a previous [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.intermediate-file-based-connectivity-smb-connectivity.WebHome||target="blank"]] we learned that we need an SMB Session Factory to set up the initial connection to the SMB drive. In this component, five main settings are relevant.
Erik Bakker 22.1 21
22 * Host
23 * Port
24 * Username
25 * Password
26 * Share and directory
27
Erik Bakker 23.1 28 In theory, each of these settings can be overwritten every time a message is consumed and processed by the flow. In practice, we see two main use cases that are relevant to mention in this microlearning as we see them currently being applied in our community.
Erik Bakker 22.1 29
30 === 3.1 Dynamic Host ===
31
Erik Bakker 23.1 32 Suppose you have a multitude of SMB directories (i.e., shares) span across many different host servers. In that case, you need a solution to manipulate pre-existing information on the SMB session factory dynamically. In other words, you need to be able to override the default host configuration in the component with one that is determined based on information in the headers or message.
Erik Bakker 22.1 33
Erik Bakker 23.1 34 To do so, we need to add a component to the flow that will override the host setting. This component is called the "Standard service activator."
Erik Bakker 22.1 35
36 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator.png]]
37
Erik Bakker 23.1 38 Here, we must define an expression to set the host based on a supplied value. Important in this expression is that we correctly reference the complete name of the SMB Session Factory support object in the flow and that once the host is set, the actual message is passed along. An example of such an expression is {{code}}@'smb.gtwydynm.exit.support.smb-session'.setHost(headers.server) ?: #root{{/code}}. This expression will set the host based on the value in the header called "server" and, once done, will pass the full message to the output channel.
Erik Bakker 22.1 39
40 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator-filled-in.png]]
41
42 === 3.2 Dynamic Share and Directory ===
eMagiz 1.1 43
Erik Bakker 23.1 44 If you have a "multi-level" path that eMagiz needs to create automatically, you must dynamically set the Share and Directory settings on the SMB Session Factory support object.
45
46 To do so, we need to add a component to the flow that will override the host setting. This component is called the "Standard service activator."
eMagiz 1.1 47
Erik Bakker 23.1 48 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator.png]]
eMagiz 1.1 49
Erik Bakker 23.1 50 Here, we must define an expression to set the host based on a supplied value. Important in this expression is that we correctly reference the complete name of the SMB Session Factory support object in the flow and that once the host is set, the actual message is passed along. An example of such an expression is {{code}}@'smb.gtwydynm.exit.support.smb-session'.setShareAndDir(headers.share) ?: #root{{/code}}. This expression will set the host based on the value in the header called "server" and, once done, will pass the full message to the output channel.
eMagiz 1.1 51
Erik Bakker 23.1 52 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator-filled-in-share-and-dir.png]]
eMagiz 1.1 53
Erik Bakker 23.1 54 {{warning}}Note that you can combine multiple dynamic settings into one expression to keep the number of components efficient. In that case the code will look something as follows {{code}}@'smb.gtwydynm.exit.support.smb-session'.setShareAndDir(headers.share) ?: @'smb.gtwydynm.exit.support.smb-session'.setHost(headers.server) ?: #root{{/code}}{{/warning}}
55
Erik Bakker 15.1 56 == 4. Key takeaways ==
eMagiz 1.1 57
Erik Bakker 23.1 58 * This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares.
eMagiz 1.1 59
Erik Bakker 15.1 60 == 5. Suggested Additional Readings ==
eMagiz 1.1 61
Erik Bakker 15.1 62 There are no suggested additional readings on this topic.)))((({{toc/}}))){{/container}}{{/container}}