不要将数据插入rethinkdb

时间:2015-05-09 12:29:46

标签: rethinkdb nsq

我正在尝试创建NSQ主题并在rethinkdb中插入数据,但我无法将数据插入rethinkdb。谁能帮我。

    Private Sub Calc()
    For Each transType In Worksheets("Sheet2").Range("C4", "C100")
    myRow = transType.Row
    oldAmount = Worksheets("Sheet2").Range("B" & myRow)
    If transType.Value = "D" Then
    newAmount.Value = oldAmount.Value * -1
    Else:
    newAmount = oldAmount
    End If
    Cells(myRow, "B").Value = newAmount
    Next transType
    End Sub

1 个答案:

答案 0 :(得分:2)

您的第二个查询(insert)似乎无法访问conn变量。为此,您需要将事件阅读器代码放在连接函数的回调中。

var nsq = require('nsqjs');
var r = require('rethinkdb');
var nsqdd = (process.env.NSQD_RETH || "localhost:4161").split(",");
var connection = null;
r.connect( {host: 'localhost', port: 28015, db:'test', authKey:''}, function(err, conn) {
    if (err) throw err;
    connection = conn;
    // Event Reader functionality inside connect callback
    var eventreader;
    eventreader = new nsq.Reader('ev_topic', 'ev_channel', {
        lookupdHTTPAddresses: nsqdd
    });
    eventreader.connect();
    eventreader.on('message', function (msg) {
        // Now we have access to the connection
        r.table('rethinkdb_test').insert(msg.json()).run(conn);
        console.log('Received message [%s]: %s', msg.id, msg.body.toString());
        msg.finish();
    });
});