解析服务器LiveQuery不响应AWS

时间:2018-01-14 16:54:23

标签: swift amazon-web-services parse-platform redis

我使用两个Parse服务器,一个用于主数据库,另一个用于liveQuery。我还通过AWS ElastiCache设置了redis。问题是当我在客户端(iOS)中使用实时查询时,没有显示任何事件。代码对任何更改都没有响应。这可能是什么问题?

一个问题:来自AWS Elasticache的redisURL是这样的:(这会在服务器启动时出错) appname.jajj2i.0001.use1.cache.amazonaws.com:6379

我应该像这样添加redis:// :(这就是我已经做过的) redis的://appname.jajj2i.0001.use1.cache.amazonaws.com:6379

我的主要解析服务器代码如下:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var S3Adapter = require('parse-server').S3Adapter
var api = new ParseServer({
    databaseURI: "main_database_uri",
    appId: "main_app_id",
    masterKey: "main_master_key",
    fileKey: "main_file_key",
    serverURL: "main_server_rul",

liveQuery: {
    classNames: ['Chats', 'Messages'],
    redisURL: 'redis_url'
  },

filesAdapter: new S3Adapter(
    "S3_Key",
    "S3_key",
    "S3_bucket_name",
    {directAccess: true}
  ),

});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var port = 1337;
app.listen(port, function() {
    console.log('parse-server running on port ' + port);
});

//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
    apps: [
        {
            appName: "My Bitnami Parse API",
            appId: "appId",
            masterKey: "masterKey",
            fileKey: "fileKey",
            production: true,
            serverURL: "serverUrl"
        }
    ],
    users: [
        {
            user: "username",
            pass: "password"
        }
    ], useEncryptedPasswords: true
});

var allowInsecureHTTP = true;

// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);

var portdash = 4040;
app.listen(portdash, function() {
    console.log('parse-dashboard running on port ' + portdash);
});

我的liveQuery服务器代码如下:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
    databaseURI: "main_database_uri",
    appId: "live_appId",
    masterKey: "live_master_key",
    fileKey: "live_file_key",
    serverURL: "live_server_url"
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var port = 1337;
app.listen(port, function() {
    console.log('parse-server running on port ' + port);
});

//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
    apps: [
        {
            appName: "My Bitnami Parse API",
            appId: "appid",
            masterKey: "masterkey",
            fileKey: "filekey",
            production: true,
            serverURL: "serverUrl"
        }
    ],
    users: [
        {
            user: "username",
            pass: "password"
        }
    ], useEncryptedPasswords: true
});

var allowInsecureHTTP = true;
// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);

var portdash = 4040;
app.listen(portdash, function() {
    console.log('parse-dashboard running on port ' + portdash);
});


var porthttp = 8030;
var httpServer = require('http').createServer(app);
httpServer.listen(porthttp, function() {
  /* Create HTTP server successfully */
});

ParseServer.createLiveQueryServer(httpServer, {
  redisURL: 'RedisUrl' // Redis URL from Main app
});

我的客户代码:

override func viewDidLoad() {
    super.viewDidLoad()

    let client = Client(server: "liveQuery_server", applicationId: "liveQuery_appId", clientKey: nil)

    Chats.registerSubclass()

    let query = PFQuery(className: "Chats").whereKey("chats", equalTo: "zaa")

    subscription = client.subscribe(query)

    subscription?.handle(Event.created) { (query, object) in

        print(object)

    }

}

1 个答案:

答案 0 :(得分:0)

import ParseLiveQuery
import BoltsSwift

let liveQueryClient: Client = ParseLiveQuery.Client(server: "wss://server.io")



 private var subscription: Subscription<PFObject>!
    var messagesArray : [PFObject] = [PFObject]()
    var msgQuery = PFQuery(className: "Inbox").whereKeyExists("message")