biztalk putting the processed file into some folder - biztalk

I have a requirement:
If I get a file, I am putting the content of that file into a database,
If there is any error in that file, I am putting it in an error folder.
Can I do something like this? Suppose I have a folder "processed" and another one "unprocessed". In case of an error, result will go in "unprocessed" and if there is no error it will go into "processed".
I don't know how to achieve that if biztalk processed some file then only put into some folder.
I suppose if I will put filter option BTS.ReceivePortName it will also put the error file into process folder.

It's very easy to create an extra send port that archives all input files.
If there's an error you just find the file, fix the issue, and re-drop it.
Create a send port, set up the filters to select the input you want (like BTS.ReceivePortName as you already know), use a pass through pipeline, then configure it as to write files. Write your files to a backup directory.
If you only want to catch errors then you will have to do extra setup. You must use an orchestration. Put a scope shape around your normal processing in the orchestration. Place an exception to catch errors on the scope shape. In the exception handler use a send shape to construct and write a copy of the original message to a send port. Add an expression to write some helpful message to the event log so you can debug the failure.

Related

Can asterisk monitor() and mixmonitor() applications be executed on same channel?

Im recording calls with Mixmonitor() application, it works fine, but recently i had a request to record each leg of call with addition to mixedfile. I know, that i can record each leg of call with Monitor() and then use external script tp mix it, but the problem is that it is additional loading of server. So I wonder can I do it by means of asterisk? For example by using Monitor and Mixmonitor together?
You can specify the call-legs with MixMonitor's parameters:
MixMonitor(mixed.wav,r(in.wav)t(out.wav))
as stated in the description:
asterisk*CLI> core show application MixMonitor
r(file): Use the specified file to record the *receive* audio feed.
Like with the basic filename argument, if an absolute path isn't given,
it will create the file in the configured monitoring directory.
t(file): Use the specified file to record the *transmit* audio feed.
Like with the basic filename argument, if an absolute path isn't given,
it will create the file in the configured monitoring directory.

Renaming files using custom pipeline in BizTalk

I tried to rename a file before sending the file to an ftp location using the SFTP adapter in BizTalk 2013. Can you help me on this ?
You need to change the FILE.ReceivedFileName property on the message to your new filename.
If you use an orchestration you can do this in an expression within a message assignment shape as follows:
OutboundMessage(FILE.ReceivedFileName) = "NewFileName.csv"
If you aren't using an orchestration you have to use a custom pipeline component.
The code to do this within the component is as follows, which goes in the pipeline component's Execute method:
pInMsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", "NewFileName.csv");
Finally in the SFTP adapter set the filename to %SourceFileName%
Hope this helps.
I believe the URL for the context is different per adapter.
The one you need is:
SFTP:
http://schemas.microsoft.com/BizTalk/2012/Adapter/sftp-properties
So in your case it would be :
pInMsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2012/Adapter/sftp-properties", "NewFileName.csv");
Thx

What would be the best practice downloading all the files from a directory using Sftp

I would like to implement the following functionality:
downloading all the files from a specified remote directory to a local directory.
after downloading all the files I need a list file which contains all the downloaded files.
(I only want this list file when all the files were downloaded successfully.)
Point 1:
Let's say we have around 10 files in the remote directory.
I can use an int-sftp:inbound-channel-adapter component to download all the files but 10 poll cycles are needed to download all of them since the inbound component is only able to download 1 file per poll request.
Spring Integration creates 10 File messages one by one.
Questions:
How can I identify the last file (message) received from the FTP server?
I don't want let users access to list file till all the files from the FTP is successfully received.
How can I achive this?
I can write file names into a list file using the int-file:outbound-channel-adapter but users can read temorary information from that file before the download process is finished.
How can I trigger the event that all files which are on the FTP are downloaded?
Thanks for your advices
Ferenc
First of all this isn't correct:
the inbound component is only able to download 1 file per poll request
You can configure it to to download infinitely during the single poll - max-messages-per-poll=-1. Anyway it is a default option on <poller>.
Anyway if it is your case to dowload one file per poll, you can go ahead with that requirements.
Since any Messaging system tries to achieve stateless paradigm, it is normal that one message doesn't know anything about another. And with that they all don't impact each other. The async scenario is the best for Messaging. With that we can process the second message quicker, than the first one.
Your requirement is enough interest and I won't dare to call it strange. Because any business may have place.
Since you are going to process several download files as one group, there will be need to have some marker on the remote server. Or it can be some timeframe, which we can extract from file timestamp. Or there will be need to store on the remote server some marker file to point that a set of files are finished and you can process them from your application using their local version. Would be great, if that marker file can contain a list of file names of that group.
Otherwise we don't have any hook to group messages for those files.
From other side you can consider to use <int-sftp:outbound-gateway> with MGET command: http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/sftp.html#sftp-outbound-gateway

Biztalk File send port with a variable path

Is it possible to make the send port change output location based on a promoted property?
We have an interface that needs to send it to a different port based on the client. But we add clients on a regular basis, so adding a new send port (both in the administrator and orchestration) will require a lot of maintenance, while the only thing that happens is a directory change
The folders are like this ...
\\server\SO\client1\Out
\\server\SO\client2\Out
\\server\SO\client3\Out
I tried using the SourceFilename to create a file name like client1\Out\filename.xml but this doesn't work.
Is there any way to do this with a single send port?
It is possible to set the OutboundTransportLocation property in context. This property contains the full path/name of the file that will be output by the file adapter. So in your case I guess you could do something along the line (if it had to be done in a pipeline component):
message.Context.Write(
OutboundTransportLocation.Name,
OutboundTransportLocation.Namespace,
string.format(#"\\server\SO\{0}\Out", client));
Of course you can do a similar thing in your orchestration.
No need of a dynamic port...

File.Create from IIS locking the created File

I have an ASP.NET running in IIS 7.5 that creates files on the local file system and then attempts to delete after performing some logic in between creation and deletion. I'm running into a situation though where deletion is failing with a response such as "The process cannot access the file 'C:...\Uploads\c1fe593f-85de-4de1-b5d1-7239e1fc0648_Tulips.jpg' because it is being used by another process.'" The file appears to be locked by IIS and I can't delete it. Here's an example of the code for creating and deleteing:
// File.WriteAllBytes(path, rawData); // this seems to leave the file open!
using (var file = File.Create(path))
{
file.Write(rawData, 0, rawData.Length);
file.Close(); // should close when it goes out of scope, but just to be safe
}
Is there some special option I need to pass into File.Create? How do I get around this?
File.WriteAllBytes(path, rawData); should work fine assuming the path parameter you are passing is unique and that you don't have concurrent requests one writing and other trying to read at the same time. To ensure this you could use a ReaderWriterLockSlim to synchronize the access if this situation could potentially occur. Also make sure that there are no other parts of the code that might leak the file handle.
Take a look at SysInternals Process Explorer which could allow you to know exactly where this file handle is leaked.

Resources