Wiki source code of SMB - Dynamically Manipulate Settings
Version 23.1 by Erik Bakker on 2024/06/21 14:47
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{container}}{{container layoutStyle="columns"}}((( | ||
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. | ||
3 | |||
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. | ||
5 | |||
6 | If you have any questions, don't hesitate to contact [[academy@emagiz.com>>mailto:academy@emagiz.com]]. | ||
7 | |||
8 | == 1. Prerequisites == | ||
9 | |||
10 | * Advanced knowledge of the eMagiz platform | ||
11 | |||
12 | == 2. Key concepts == | ||
13 | |||
14 | This microlearning centers around dynamically manipulating settings on the SMB Session Factory. | ||
15 | |||
16 | * This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares. | ||
17 | |||
18 | == 3. Dynamically manipulate SMB Session Settings == | ||
19 | |||
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. | ||
21 | |||
22 | * Host | ||
23 | * Port | ||
24 | * Username | ||
25 | * Password | ||
26 | * Share and directory | ||
27 | |||
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. | ||
29 | |||
30 | === 3.1 Dynamic Host === | ||
31 | |||
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. | ||
33 | |||
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." | ||
35 | |||
36 | [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator.png]] | ||
37 | |||
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. | ||
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 === | ||
43 | |||
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." | ||
47 | |||
48 | [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator.png]] | ||
49 | |||
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. | ||
51 | |||
52 | [[image:Main.Images.Microlearning.WebHome@advanced-file-connectivity-dynamically-manipulate-smb-settings--standard-service-activator-filled-in-share-and-dir.png]] | ||
53 | |||
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 | |||
56 | == 4. Key takeaways == | ||
57 | |||
58 | * This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares. | ||
59 | |||
60 | == 5. Suggested Additional Readings == | ||
61 | |||
62 | There are no suggested additional readings on this topic.)))((({{toc/}}))){{/container}}{{/container}} |