0

I tried to put together a Horizon app with an externally hosted RethinkDB and I couldn't seem to get it to work with existing tools. I understand Horizon includes a server-side API component, which may be why.

I want to be able to directly insert and/or update documents in my RethinkDB from an external server, and have those updates be pushed to subscribed browsers. Is this possible and/or wise?

Preferably this would not involve my Horizon express server at all. I would prefer to not have to expose my own API to do this.

Erik J
  • 828
  • 9
  • 22
  • Is the server listening on an accessible interface (0.0.0.0)? Have you tried using the native rethinkdb driver and passing it the host and port addresses for the rethink server? This really has nothing to do with horizon, since from the rethinkdb's perspective it is just like any other client. Also you will have to configure permissions, etc so that your server is secure and inaccessible to others. – AlanZ2223 Aug 09 '16 at 14:47
  • Hey Erik J, this is definitely possible but I need some more information to help you connect the dots. From what I understand, you want to have a separate service push data into RethinkDB and have it accessible by Horizon? – dalanmiller Aug 11 '16 at 19:10
  • Did you figure this out? – dalanmiller Aug 23 '16 at 17:50

1 Answers1

0

This is totally possible as long as the RethinkDB instance is visible to the service pushing data into RethinkDB in some way. You'd then just connect to RethinkDB via a standard driver connection with your language of choice. A simple in Python would look like this:

import rethinkdb as r

conn = r.connect('localhost', 28015)
r.db("horizon_project_name").table("things").insert({'text': 'Hello, World!'}).run(conn) 

Then when you start Horizon, you'll want to make sure to use the --connect flag and provide the hostname and port of that same RethinkDB instance.

An example, if RethinkDB is running on the same machine as Horizon:

hz serve --connect localhost:28015

In Horizon, you'd be able to listen to these messages like so in the browser:

const horizon = Horizon();
horizon('things').subscribe((result) => {
  // `result` is the entire collection as an array
  console.log("result!", result); 
});

If you need futher help with this, feel free to tweet me @dalanmiller or create a new topic in discuss.horizon.io!

dalanmiller
  • 3,467
  • 5
  • 31
  • 38