Grails的 - 与第三方API异步通信 [英] Grails - asynchronous communication with 3rd party API

查看:213
本文介绍了Grails的 - 与第三方API异步通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我为了一个在线交易平台,界面Grails的实验。结果
特别是盈透证券(IB) http://interactivebrokers.com/en/p .PHP F = programInterface&放大器; ib_entity = LLC

该API的工作方式是,你需要有自己的客户端程序,交易平台(TWS的 http://interactivebrokers.com/en/p.php?f=tws&ib_entity=llc )运行,然后我们所消耗的API做的东西。消耗API基本上涉及创建一个经纪人的对象,调用连接()成员函数(这使得该交易平台软件的本地端口连接),并呼吁类似的getData()

The way the API works is you need to have their client program, Trader Workstation (TWS http://interactivebrokers.com/en/p.php?f=tws&ib_entity=llc) running and then we consume the API to do stuff. Consuming the API basically involves creating a "broker" object, calling a connect() member function (this makes a local port connection to the TWS software) and calling something like getData()

的Grails在这种情况下的价值是提供的格姆功能和Web框架。我希望能够定义从数据库提取的实施对象,很容易做到持久性的操作,方便地为用户提供一个UI做CRUD和自定义操作。

The value of grails in this scenario are the GORM features and the web framework provided. I want to be able to define objects abstracted from db implementation, easily do persistance operations and easily provide users with a UI to do CRUD and custom actions.

我的挑战是IB API使用的请求和应答的异步通信。即当我打电话的getData(),该API知道使用回调函数dataResults(),当它准备送他们。为了dataResults()可以被调用,我创建还是经纪人对象需要大约收到答复。结果
内部控制器功能,如果我创建了一个代理对象并调用的getData(),当请求完成后,经纪人对象显然也消失了。因此,我将永远无法收到答复。

My challenge is the IB API uses asynchronous communication for requests and replies. i.e. when i call getData(), the API knows to use the callback function dataResults() when it is ready to send them. In order for dataResults() to be callable, the broker object I created still needs to be around to receive the reply.
Inside a controller function, if i create a broker object and call getData(), when the request finishes, the broker object obviously also disappears. So I'll never be able to receive the reply.

我觉得可能是某种方式拉开后台线程来做到这一点,但我不知道这是我想往下走的路径。

I think there might be some way to do this by kicking off background threads but i'm not sure this is the path i want to go down.

有没有人有最好的方法是什么什么建议?结果
我没有结婚到Grails的,我使用它的原因是以上。如果有一个桌面应用程序框架,我也可以很容易地在顶部的Web界面后,我肯定持开放的态度。

Does anyone have any recommendations on what the best approach is?
I'm not married to grails, the reasons i'm using it are above. If there is a desktop app framework that I can also easily make a web interface on top of later, I'm definitely open to that.

先谢谢了。

推荐答案

创建服务你的对象和的使服务单(这是默认设置):

Create your object in Service and make the Service singleton (which is by default):

static scope = "singleton"

这篇关于Grails的 - 与第三方API异步通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆