The QuickStartConsumer example code retrieves market price for given currency RIC as a stream of data. The data keeps on coming as a response event and displayed on console. How do I retrieve a market price at a snap of a time? Are there any examples for this method, like if I want to retrieve current exchange rate for GBPINR on click of a button?
I recommend you work through the tutorials - as this will give a good overview of how RFA works including dispatching, connection events etc and most likely save you time in the long run.
As mentioned previously QuickStartConsumer is a very basic example.
You will initially get 'Source unavailable' because you have made a connection request, sent a Login request and an item request immediately after each other. i.e. requesting an item before you are fully connected and logged in and so the API is just letting you know that the source you are requesting data from is not yet available.
Just remember that RFA.NET works asynchronously - i.e. you send your requests and the responses arrive asynchronously.
Therefore, if you were to wait till the connection was made and successful Login - before sending the item request then you should not see the 'Source unavailable' message - assuming the service was up and running.
With regard the dispatching, you should really be dispatching continuously. This will ensure your application receives any relevant events such as logged out, service down, connection lost (assuming you have registered interest in connection events - which you should). You can use this information to keep your application user informed of the login / connection status etc.
Are you using EMA or RFA.NET - please confirm?
I will assume you are using RFA.NET based on the example name and your earlier questions...
If you don't want streaming data - only snapshot - then remove the
from ReqMag.InteractionType when making the GBPINR item request.
So, for your click button scenario you would need to make the item request i.e populate the ReqMsg and call RegisterClient etc, when the button is clicked.
As it is a snapshot request, the item stream will be closed by the API once it has provided the InitialImage (i.e. snapshot). So, you will need to re-request it each time someone presses the button.
It is also possible to pause and resume the stream, i.e. pause the stream once you get the rate and resume when someone clicks the button and then pause again as soon as you get the rate and so on....
You only need to call registerClient for the required RIC each time you want a snapshot.
You don't need to re-initialise RFA, create queue, Login etc each time.
Also, as mentioned - when making a snapshot request, the API will close the event stream once it has delivered the Image/Refresh - so you don't need to call unregisterClient for the RIC item each time.
You should only need to call unregisterClient for the Login Handle, release, destroy - i.e. the cleanup code when you terminate the application.
So, yes you are correct in your last sentence about what to do at startup, each button click and for shutdown.
The session should persist indefinitely, unless connectivity is lost or planned/unplanned Elektron Server downtime etc. Even when connection is lost etc, the API will attempt to re-establish a connection on your behalf when possible. Please refer to the documentation for further details on recovery / retry etc.
NOTE: The QuickStartConsumer is a very basic example and therefore should not be used for production purpose. I recommend you work through the RFA.NET tutorials and also refer to the RFA C++ tutorials for additional guidance - and use what you learn to write your own application.
For example the QuickStartConsumer uses local data dictionary files - which is not advisable for a production application - as they change quite often. You should really download these from the server - as demonstrated in the RFA C++ Tutorial Step 10.
You can also refer to the fuller RFA.NET Consumer example for code which demonstrates how to download the dictionary.