I am writing a program that uses the quickfix library. The documentation is very poor, so I am requesting the help of SO fellows.
I have seen in the Group class that there are iterators. So I suppose that there is some STL-ish way of parsing repeating groups. Am I wrong?
Can anybody provide a simple example for doing that?
Thank you very much in advance.
Use Quickfix library alongwith the documentation of how FIX messages are constructed. Else it would be very difficult to decipher how the messages are organized.
This is an example from Quickfix website
Your message is the MarketDataSnapshotFullRefresh class object.
FIX::NoMDEntries noMDEntries;
message.get(noMDEntries); ->
You get the count of repeating groups, how many times you need to iterate over the object message to get all the entries. Remember FIX::NoMDEntries is a field.
FIX42::MarketDataSnapshotFullRefresh::NoMDEntries group; ->
This is a little tricky. You go inside a message to get the groups. Here NoMDEntries is an enclosed class inside MarketDataSnapshotFullRefresh class. Remeber this is the class which will give you the data. Now either you run through a loop or write the same code multiple times to extract all the fields inside each group. getGroup gives you the group from which you extract fields. getField will give you the field data. Most of the nomenclature of Quickfix is FIX messages. So refer a FIX message website like Fiximate and your life will be much easier.
FIX::MDEntryType MDEntryType;
FIX::MDEntryPx MDEntryPx;
FIX::MDEntrySize MDEntrySize;
FIX::OrderID orderID;
message.getGroup(1, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);
message.getGroup(2, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);
There are iterators in FieldMap class which is a super class of Message and Group class.
I'm not sure what do you mean by parsing repeating groups.
Fix engine parses raw fix messages for you when they arrive and your callback gets parsed FIX message - which has internal maps of tags (key/value) for tags in message header, body and tail.
Looking at 1.13.2 version of code, when the engine gets new string message from network it will eventually create a Message passing it the string. Message constructor then calls setString() on itself which effectively parses the received string and creates a map of tags.
If you look at Message::setString you can see that first the new field is added and then in setGroup it checks if the field is part of the group. If it is then this method, setGroup, takes over parsing of the following tags while those tags are part of the group. Once it comes across of tag that is not part of the group it stops parsing the group, it returns and continues parsing fields from message.
Now this all happens internally before the callback to your app where you handle received message.
There is a way to iterate over fields in a message. You can iterate over fields of header, body or over groups (and over each group).
const FIX40::ExecutionReport& msg; // new incoming message
// iterate over header
FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.getHeader().begin();
FIX::FieldMap::iterator e = msg.getHeader().end();
for(it = b; it != e; ++it)
{
switch(it->first)
{
case FIX::FIELD::MsgSeqnum:
/* it->second.getString() - do something with tag data*/ ;
break;
...
}
}
And similarly for body:
FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.begin();
FIX::FieldMap::iterator e = msg.end();
And there is groups iterator (FieldMap::g_begin/g_end) as well so you could iterate over groups in msg or header and you can similarly iterate, or search, tags within each group.
Group as well as Message extends FieldMap so all the getField/setField functionality is shared across.
Internals ... skip if too much detail.
In the above example this code:
message.getGroup(1, group);
group.get(MDEntryType);
Effectively passes the call from message.getGroup(1, group) -> FieldMap::getGroup(1, group.field(), group) -> getGroupRef(num,field) -> m_groups.find(field) which gives you a vector of groups (vector<FieldMap*>) and returns the num element, aka the num group from the message (a FieldMap).
group.get(field) is created using macros for each tag which is effectively translated as (map).getField(field).
During initialization the (map) for group is a reference to the object of which the tag is member of so it returns the tag from the specific group (see example src/C++/fix44/NewOrderSingle.h it has couple of internal classes which extend Group)
Hope that it makes some sense.
Related
I have created a rule where the subject line contains
A Document has been assigned to You
It also routes the emails with subject
A Document has been assigned to Your group
How can I fix this? Is there a regular expression available?
You can develop a VBA macro that can handle incoming emails. The NewMailEx event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance.
Public WithEvents outApp As Outlook.Application
Sub Intialize_Handler()
Set outApp = Application
End Sub
Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
Dim mai As Object
Set mai = Application.Session.GetItemFromID(EntryIDCollection)
MsgBox mai.Subject
End Sub
You can use regular expression in VBA macros, see How to Use/Enable (RegExp object) Regular Expression using VBA (MACRO) in word for more information.
I am trying to use IBM MQ client 9 with C++. I would like to read only messages that has group id '2'. I have tried everything but it just does not work. Can someone assist please?
I tried to set groupId and flag to match on group.
MQGET
gmoptions.setMatchOptions(MQMO_MATCH_GROUP_ID);
MQBYTE24 bGroupId("2");
ImqBinary _groupId;
_groupId.set(bGroupId, sizeof(bGroupId));
message.setGroupId(_groupId);
q->get(message, gmoptions);
MQPUT
MQBYTE24 bGroupId("2");
ImqBinary _groupId;
_groupId.set(bGroupId, sizeof(bGroupId));
message.setGroupId(_groupId);
ImqPutMessageOptions pmo;
pmo.setOptions(MQPMO_LOGICAL_ORDER);
pmo.setRecordFields(MQPMRF_GROUP_ID);
q->put(message, pmo);
mqget should be able to get all the msgs with groupId "2" but it does not. Though it can read the msg as soon as I remove setMatchOptions.
Basically, I want to use Group Id as filter where server instance 1 will read msgs only in group1 and server instance 2 will read msgs only in group 2 and so on, instead of creating separate queues for each server instance.
May be following can help me if group id is only for batching instead of filtering though not sure how to do 'Selection using the MQSUB and MQOPEN function calls' in C++
https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q022990_.htm
Is there any C++ equivalent of MQSETMP ? I am unable to find any interface in ImqQueue or ImqObject that will let me set message property or selectionString.
I don't think you are going about this the right way.
IBM published a Java/MQ sample program to get messages in a group called GetGroup.java. You can find it here. You can use it as a model for your C++ program.
Basically, the code retrieves a message from the queue and then checks the messageFlags field if the message is part of a group.
if ((myMessage.messageFlags & CMQC.MQMF_MSG_IN_GROUP) == CMQC.MQMF_MSG_IN_GROUP)
If the message is part of the group then the code sets the matchOptions for matching on a group and retrieves all of the messages in the group.
Note: You will probably want to add logical order to the GMO options.
gmo.options |= CMQC.MQGMO_LOGICAL_ORDER;
Finally, what is this?
pmo.setRecordFields(MQPMRF_GROUP_ID);
That doesn't make any sense. You should be setting messageFlags field to MQMF_MSG_IN_GROUP.
You can use the concept of SELECTORS in IBM MQ. A message selector is a variable-length string used by an application to register its interest in only those messages that have properties that satisfy the Structured Query Language (SQL) query that the selection string represents.
A message selector is a concept that has been in the JMS specification for a long time. It
is a way of limiting the messages that are passed to an application to those that meet
certain criteria. Those criteria are based on the values of the message properties and only
the value of the message properties. It is important to understand that selection cannot be
based on any values of the message payload, only on the message property values.
In your case, the PUT application will have to put messages with populating the a certain topic string in MQMD or MQRFH2 header and using MQ Interface function calls, you should be able to pick the messages only with a certain value which in your case is GroupId value.
Below are few reference links to the concept:
https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.dev.doc/q022990_.htm
http://publib.boulder.ibm.com/infocenter/ieduasst/v1r1m0/topic/com.ibm.iea.wmq_v7/wmq/7.0/MQI/iea_330_wmqv7_API_3_Selectors.pdf ==> Pdf gets downloaded
To understand Message Properties => https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q022920_.htm
Suppose I have a proto structure that looks like the following:
message TMessage {
optional TDictionary dictionary = 1;
optional int specificField1 = 2;
optional TOtherMessage specificField2 = 3;
...
}
Suppose I am using C++. This is the message stub that is used in the master process to send information to the bunch of the nodes using the network. In particular, the dictionary field is 1) pretty heavy 2) common for all the serialized messages, and all the following specific fields are filled with the relatively small information specific to the destination node.
Of course, dictionary is built only once, but it comes out that the major part of running time is spent while serializing the common dictionary part again and again for each new node.
Obvious optimization would be to pre-serialize dictionary into the byte string and put it into the TMessage as a bytes field, but this looks a bit nasty to me.
Am I right that there is no built-in way to pre-serialize a message field without ruining the message structure? It sounds like an idea for a good plugin for proto compiler.
Protobuf is designed such that concatenation === composition, at least for the root message. That means that you can serialize an object with just the dictionary, and snapshot the bytes somewhere. Now for each of the real messages you can paste down that snapshot, and then serialize an object with just the other fields - just whack it straight after: no additional syntax is required. This is semantically identical to serializing them all at the same time. In fact, since it will retain the field order, it should actually be identical bytes too.
It helps that you used "optional" throughout :)
Marc's answer is perfect for your use case. Here is just another option:
The field must be a submessage, like your TDictionary is.
Have another variant of the outer message, with bytes in place of the submessage you want to preserialize:
message TMessage_preserialized {
optional bytes dictionary = 1;
...
}
Now you can serialize the TDictionary separately and put the resulting data in the bytes field. In protobuf format, submessages and bytes field are written out the same way. This means you can serialize as TMessage_preserialized and still deserialize as normal TMessage.
I am trying to write a REST service with Jersey where the GET method should write me a list of objects. The input to the GET method should take the ids of the list.
Say I will pass n numbers of EmployeeId and the service should return me a list of employees.
If it is not possible to have #Consumes in the GET method, will there be any problem in using other methods of http like PUT or POST to retrieve the list of objects?
Using POST and PUT for resource retrieval contradicts the conventions established for the usage of REST over HTTP. Switching to either of them just for the sake of using a #Consumes annotation is simply wrong.
If you need to provide additional scoping information for a collection of resources, place it in the URL. Specifically, you can use query parameters. It's a common pattern to implement pagination this way (by providing some limit and offset parameters). Your use case is very similar.
Let's assume this is the URL of a collection of employee resources
GET http://www.example.com/employees
A single employee could be fetched like this:
GET http://www.example.com/employees/id1
If you want to retrieve several employees, you could use a query string like this:
GET http://www.example.com/employees?ids=id1;id3;id8
The identifiers do not need to be delimited by semicolons, this is just an example of a way you could fetch them. Remember that it's treated as a single parameter! You'll have to split the values.
Here's how you could read such a list from the URL above
#Path("employees")
#GET
public Response getEmployees(#QueryParam("ids") String employees){
List<String> ids = Arrays.asList(employes.split(";"));
// Validate the ids, get data from a database,
// prepare a response and return it
}
Parsing the list can be cumbersome, especially if you want to validate the ids somehow. Jersey has a neat feature you can use here. If a class has a single-string-parameter constructor or a SomeType parse(String) method, it can be injected by the framework by parsing the string passed as a parameter (QueryParam, PathParam, FormParam, etc.)
You can take advantage of it to make your resource class cleaner.
#Path("employees")
#GET
public Response getEmployees(#QueryParam("ids") Employees e){
doFancyStaffWithAValidListOfEmployees(e.asList());
//prepare a response
}
Where Employees is a class with a String constructor or a parse method, containing all the splitting and validation logic, possibly even some database queries.
Here's a nice article on writing such parameter classes
If I'm not mistaken, it seems that FinalBuilder 7's action list parameters only support input values. Is there any way I can simulate a workaround for return parameters? I do not want to store return parameters in a global temp variable or even a stack, because I'm calling the same action list multiple times asynchronously.
Here is sample of what I want to do. (Notice the shared use of the same action list)
Async Action Group
+-Action Group
| +-Run Action List - [Do Some Calculation]
| +-Replace variable A with return parameter from previous action list
+-Action Group
+-Run Action List - [Do Some Calculation]
+-Replace variable B with return parameter from previous action list
I'm currently using an INI file in the action list to save return values. The calling method passes a parameter to the action list specifying to which INI key to save to. The calling method then reads the value from the INI from the key.
Surely there has to be a more elegant way to do this?
I have never seen any way to return variables from action lists.
That would be an excellent suggestion to post in the FinalBuilder Wish List forum.
Many of requests in the past there are now features of the product.
I think it would require giving scope to variables to something like an Action Group to pull it off. But it would help some of my scripts as well. Update: I found that FB 7 supports Local Variables. But it still does not address the needs of this answer.