Search in sources :

Example 1 with QueueQuery

use of cn.cerc.jdb.queue.QueueQuery in project summer-mis by cn-cerc.

the class AsyncService method exec.

@Override
public boolean exec(Object... args) {
    if (args.length > 0) {
        Record headIn = getDataIn().getHead();
        if (args.length % 2 != 0)
            throw new RuntimeException("传入的参数数量必须为偶数!");
        for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
    }
    String subject = this.getSubject();
    if ("".equals(subject))
        throw new RuntimeException("后台任务标题不允许为空!");
    // 发送到队列服务器
    this.send();
    getDataOut().getHead().setField("_msgId_", msgId);
    if (this.process == 2) {
        // 返回消息的编号插入到阿里云消息队列
        QueueQuery ds = new QueueQuery(handle);
        if (ServerConfig.getAppLevel() == ServerConfig.appTest) {
            ds.add("select * from %s", QueueDB.TEST);
        } else {
            ds.add("select * from %s", QueueSession.defaultQueue);
        }
        ds.open();
        ds.appendDataSet(this.getDataIn(), true);
        ds.getHead().setField("_queueId_", msgId);
        ds.getHead().setField("_service_", this.service);
        ds.getHead().setField("_corpNo_", this.corpNo);
        ds.getHead().setField("_userCode_", this.userCode);
        ds.getHead().setField("_content_", this.toString());
        ds.save();
    }
    return !"".equals(msgId);
}
Also used : Record(cn.cerc.jdb.core.Record) MessageRecord(cn.cerc.jmis.message.MessageRecord) QueueQuery(cn.cerc.jdb.queue.QueueQuery)

Example 2 with QueueQuery

use of cn.cerc.jdb.queue.QueueQuery in project summer-mis by cn-cerc.

the class MessageQueue method send.

public void send(IHandle handle) {
    if (subject == null || "".equals(subject)) {
        throw new RuntimeException("消息标题不允许为空");
    }
    if (userCode == null || "".equals(userCode)) {
        throw new RuntimeException("用户代码不允许为空");
    }
    String sendCorpNo = corpNo != null ? corpNo : handle.getCorpNo();
    if ("".equals(sendCorpNo)) {
        throw new RuntimeException("公司别不允许为空");
    }
    // 将消息发送至阿里云MNS
    QueueQuery query = new QueueQuery(handle);
    query.setQueueMode(QueueMode.append);
    if (ServerConfig.getAppLevel() == ServerConfig.appTest) {
        query.add("select * from %s", QueueDB.MESSAGE_TEST);
    } else {
        query.add("select * from %s", QueueDB.MESSAGE);
    }
    query.open();
    Record headIn = query.getHead();
    headIn.setField("CorpNo_", sendCorpNo);
    headIn.setField("UserCode_", userCode);
    headIn.setField("Level_", level.ordinal());
    headIn.setField("Process_", process);
    headIn.setField("Subject_", subject);
    headIn.setField("Content_", content.toString());
    query.save();
}
Also used : Record(cn.cerc.jdb.core.Record) QueueQuery(cn.cerc.jdb.queue.QueueQuery)

Example 3 with QueueQuery

use of cn.cerc.jdb.queue.QueueQuery in project summer-mis by cn-cerc.

the class ProcessQueue method execute.

@Override
public void execute() throws Exception {
    QueueQuery query = new QueueQuery(this);
    query.setQueueMode(QueueMode.recevie);
    query.add("select * from %s ", QueueSession.defaultQueue);
    query.open();
    if (!query.getActive())
        return;
    query.remove();
    // 建立服务执行环境
    String corpNo = query.getHead().getString("_corpNo_");
    if ("".equals(corpNo)) {
        log.error("_corpNo_ is null");
        return;
    }
    String userCode = query.getHead().getString("_userCode_");
    if ("".equals(userCode)) {
        log.error("_userCode_ is null");
        return;
    }
    String service = query.getHead().getString("_service_");
    if ("".equals(service)) {
        log.error("_service_ is null");
        return;
    }
    // 调用队列内容中指定的服务
    BookHandle bh = new BookHandle(this, corpNo);
    bh.setUserCode(userCode);
    LocalService svr = new LocalService(bh);
    svr.setService(service);
    svr.getDataIn().appendDataSet(query, true);
    String msgId = query.getHead().getString("_queueId_");
    JSONObject content = JSONObject.fromObject(query.getHead().getString("_content_"));
    LocalService app = new LocalService(bh, "SvrUserMessages.updateAsyncService");
    if (svr.exec()) {
        content.element("processTime", TDateTime.Now());
        content.element("dataOut", svr.getDataOut().getJSON());
        if (!app.exec("msgId", msgId, "process", MessageProcess.ok.ordinal(), "content", content.toString()))
            log.error(app.getMessage());
    } else {
        content.element("processTime", TDateTime.Now());
        content.element("dataOut", svr.getDataOut().getJSON());
        if (!app.exec("msgId", msgId, "process", MessageProcess.error.ordinal(), "content", content.toString()))
            log.error(app.getMessage());
    }
}
Also used : JSONObject(net.sf.json.JSONObject) LocalService(cn.cerc.jbean.client.LocalService) BookHandle(cn.cerc.jbean.core.BookHandle) QueueQuery(cn.cerc.jdb.queue.QueueQuery)

Aggregations

QueueQuery (cn.cerc.jdb.queue.QueueQuery)3 Record (cn.cerc.jdb.core.Record)2 LocalService (cn.cerc.jbean.client.LocalService)1 BookHandle (cn.cerc.jbean.core.BookHandle)1 MessageRecord (cn.cerc.jmis.message.MessageRecord)1 JSONObject (net.sf.json.JSONObject)1