SMB - Dynamically Manipulate Settings
In a previous microlearning 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.
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.
If you have any questions, don't hesitate to contact academy@emagiz.com.
1. Prerequisites
- Advanced knowledge of the eMagiz platform
2. Key concepts
This microlearning centers around dynamically manipulating settings on the SMB Session Factory.
- This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares.
3. Dynamically manipulate SMB Session Settings
In a previous microlearning 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.
- Host
- Port
- Username
- Password
- Share and directory
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.
3.1 Dynamic Host
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.
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."
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:
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.
3.2 Dynamic Share and Directory
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.
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."
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:
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.
3.3 Additional Dynamic Options
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.
3.3.1 Port
3.3.2 Username
3.3.3 Password
4. Key takeaways
- This option is the correct approach when you need to create a directory dynamically or have multiple hosts that host file shares.