Last modified by Erik Bakker on 2024/09/03 09:17

Hide last authors
Erik Bakker 6.1 1 {{container}}{{container layoutStyle="columns"}}(((
Erik Bakker 24.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
Carlijn Kokkeler 30.1 4 In this microlearning module, we’ll delve into dynamically manipulating settings on the SMB Session Factory. This approach is particularly useful when you need to create directories on-the-fly or manage file shares across multiple hosts. We’ll explore how to configure dynamic settings such as host, share, and directory using the Standard Service Activator, and discuss additional dynamic options to enhance flexibility in your SMB configurations.
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
Bouke Reitsma 25.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:
Erik Bakker 27.1 39
Bouke Reitsma 25.1 40 {{code}}@'smb.gtwydynm.exit.support.smb-session'.setHost(headers.server) ?: #root{{/code}}
Erik Bakker 27.1 41
Bouke Reitsma 25.1 42 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 43
44 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator-filled-in.png]]
45
46 === 3.2 Dynamic Share and Directory ===
eMagiz 1.1 47
Erik Bakker 23.1 48 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.
49
50 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 51
Erik Bakker 23.1 52 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator.png]]
eMagiz 1.1 53
Bouke Reitsma 25.1 54 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:
Erik Bakker 27.1 55
Bouke Reitsma 25.1 56 {{code}}@'smb.gtwydynm.exit.support.smb-session'.setShareAndDir(headers.share) ?: #root{{/code}}
Erik Bakker 27.1 57
Bouke Reitsma 25.1 58 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 59
Erik Bakker 23.1 60 [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator-filled-in-share-and-dir.png]]
eMagiz 1.1 61
Erik Bakker 23.1 62 {{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}}
63
Erik Bakker 26.1 64 === 3.3 Additional Dynamic Options ===
65
66 Although we don't think these options will be used much we define them here for the sake of completeness and give you examples on how to make these additional values dynamically.
67
68 ==== 3.3.1 Port ====
69
70 {{code}}@'smb.gtwydynm.exit.support.smb-session'.setPort(headers.port) ?: #root{{/code}}
71
72 ==== 3.3.2 Username ====
73
74 {{code}}@'smb.gtwydynm.exit.support.smb-session'.setUsername(headers.username) ?: #root{{/code}}
75
76 ==== 3.3.3 Password ====
77
78 {{code}}@'smb.gtwydynm.exit.support.smb-session'.setPassword(headers.password) ?: #root{{/code}}
79
Erik Bakker 15.1 80 == 4. Key takeaways ==
eMagiz 1.1 81
Erik Bakker 23.1 82 * 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 83
Erik Bakker 15.1 84 == 5. Suggested Additional Readings ==
eMagiz 1.1 85
Carlijn Kokkeler 29.1 86 * [[Intermediate (Menu)>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.WebHome||target="blank"]]
87 ** [[File based connectivity (Navigation)>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.WebHome||target="blank"]]
88 *** [[SMB Connectivity (Explanation)>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.File based connectivity.intermediate-file-based-connectivity-smb-connectivity.WebHome||target="blank"]]
Erik Bakker 31.1 89 * [[SMB (Search Result)>>url:https://docs.emagiz.com/bin/view/Main/Search?sort=score&sortOrder=desc&highlight=true&facet=true&r=1&f_space_facet=1%2FMain.eMagiz+Academy.&f_type=DOCUMENT&f_locale=en&f_locale=&f_locale=en&text=%22smb%22||target="blank"]]
Carlijn Kokkeler 29.1 90 )))((({{toc/}}))){{/container}}{{/container}}