Rails w/custom TCP data service -


I am building a Rail App that needs to be connected to custom TCP data service, which exchanges exchange data -Usages to provide. Functionally, this is not a problem, but I'm having difficulty in architecting it in a way that is considered "clean".

Short overview:

The user logs in to the log app, on login, the credentials are valid with the data service and the "reference ID" has been returned.

Request:

  & lt; Login & gt; & Lt; Username & gt; Testuser & lt; / Username & gt; & Lt; Password & gt; Mypass & lt; / Password & gt; & Lt; / Login & gt;  

Answer:

   

This context_id is basically a session token.

Request:

  & lt; History & gt; & Lt; Context_id & gt; 123456 and lieutenant;  

; / Context_id & gt; & Lt; Start_date & gt; 1/1/2010 and lt; / Start_date> & Lt; End_date & gt; 1/31/2010 and lt; / End_date & gt; & Lt; / History & gt;

Feedback:

  & lt; Answer & gt; & Lt; History_item & gt; ... & lt; / History_item & gt; & Lt; History_item & gt; .. & lt; / HISTORY_ITEM & gt; & Lt; / Responses & gt;  

I have hidden all XML creation / parsing in my model, which is working really well, I can store context_id in the user's session, I can get it in, send it to the model function

  @transactions = Transaction.find ({: context_id = & gt; 123456 ,: start_date = & gt; 1/1/2010 ',: end_date = & gt; 1/31 / 2010>}  

From a design point of view, I have 2 problems like i solve:

  1. context_id for each model operation Passing is a bit of a pain. It would be nice if the model can retrieve the ID only from session, but I know that it separates the rule of concerns.
  2. There is a TcpSocket connection that is created / destroyed on every model request. The connection is not directly connected to context_id, so it would be good if the socket can be stored elsewhere and is retrieved by the model, so I'm not reinstating the connection for each request.

This may seem really complicated, and I'm probably going about all this wrong, if someone has any ideas then I would love to hear it.

Technical Details: I am running Apache / Mode_R, and I have 0 controls on TCP service and it has architecture.

Consider moving API access to a new class, and TcpSocket Store the example and reference ID there. Instead of talking to your models with socket, talk to this API access class to change.

Add a controller (that) to remove the reference ID from the session, add a around_filter , store it in the API access class, and after performing the action, it nits. is. Unless your rail processes are single-threaded, you'll be fine. If you switch to multi-threaded model, you will need to change the API access class to store the reference ID and in the TcpSocket thread-local memory, and you A TcpSocket will be required per thread.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -