Wednesday, September 19, 2012

This post explains how you can read file in OSB. You can read any type of file like you can do in SOA.

Follow below steps to read file in Oracle Service Bus.

Step 1.) Create new OSB project and Proxy Service.

  • First of all create Session by clicking on "Create" Button and then click on "Project Explorer" to create new project.
Create Session
  • Enter the name of the project "ReadFile" and add it.
Create New Project
  • Now click on newly created project "ReadFile" to add new folders.
Read File Project
  • Add "proxyService" folders which contains proxy service that will poll/read the file from given location.

Proxy Service
  • Now click on newly created "proxyService" folder to create proxy service and choose "Proxy Service" as Resource Type.
Service Resource Type

Step 2.) Fill details in Proxy Service to read/poll file.
  • Enter proxy service name and choose "Service Type" as "Messaging Service". Click on "Next" button.
Proxy Service name and type


  • Choose "Request Message Type" based on what type of file you want to read/poll. In my case its text file so I will choose "Text". Choose "Response Message Type" as "None" because we don't need any response after reading the file. Click on "Next" button.
Request Message Type
  • Choose "file" protocol from drop down list.
file protocol
  • Provide the "Endpoint URI". Click on "Next" button.
                   file:///{Drive Id}/filedir/


file directory
  • Next step is to provide File Transport Protocol details. 
    • File Mask: Default value is *.* that means you can send any type of file to the service. I created "test.txt" file in C:/read directory for this post.
    • Polling Interval: It specifies the number of seconds between each polling event. Leave it as default.
    • Read Limit: It specifies the maximum number of files to process during each polling event.Default value is 10. If you set it to 0 that means all files that match the file mask at the time of polling event will be processed. Leave it as default.
    • Sort By Arrival : It forces the selection of files while polling based on their creation date. Remain it unchecked.
    • Scan SubDirectories: It says OSB proxy look for files recursively in any existing subdirectories. Leave it unchecked.
    • Pass By Reference : It tells copy the file to archive directory and pass a reference to the file in the message itself. Leave it unchecked.
    • Post Read Action: It tells we can either delete the file or archive the file after the message has been processed. Choose "delete" for this sample.
    • Stage Directory : It specifies where the files should be stored while they are being processed. So while polling, OSB first move file from polling directory to stage directory and process file from there.
    • Archive Directory : Directory where we want to archive the file. This will not be available if you choose "delete" as Post Read Action.
    • Error Directory: Directory where file will be sent of there is any problem or issue. 
File Transport Protocol Properties
  • Accept default values and you are done with your proxy service. 
  • Activate the session and to test proxy service put test.txt file in C:./read directory.
Create Business Service as per your requirement how you want to process file message.


Go through next post which explain how to write file in Oracle Service Bus.
                   
                                Write file in OSB
       

4 comments :

  1. Hello Vivek,

    Suppose there are a large number of files that are being added and they need to be deleted once they are read.
    Over a period of time, there arises a situation that the files are being added, but the OSB is not being able to delete them at the required rate, thus affecting the processing.

    What can be done in this scenario?

    ReplyDelete
    Replies
    1. Hi Pratik,

      OSB always move the file to stage directory before it start to read it so I don't think OSB will not be able to delete the file, if it can read the file.

      Delete
  2. Hi Vivek,
    I have 1 scenario, wherein we need read file from multiple directory. Can you please tell me how we can add multiple directory into the Endpoint URI.

    ReplyDelete
  3. Hi,

    I have a scenario where I wanna place files in the target with different file system (apart from the landing directory File system). How can i achieve that?
    Thanks in advance!!!

    ReplyDelete