activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

Setting up with Neo4j 4.0.x WITHOUT Rails?

Open Joshfindit opened this issue 4 years ago • 1 comments

Currently getting connection failures, which I assume are due to running 9.6.2, so I'm looking to get this running with the 10.0.x code

Additional information which could be helpful if relevant to your issue:

Code example (inline, gist, or repo)

This is what used to work

Gemfile

gem 'sinatra'
gem 'neo4j'

app.rb

require 'json'
require 'jsonapi-serializers'
require 'neo4j'
require 'neo4j/core/cypher_session/adaptors/http'
require 'neo4j/core/cypher_session/adaptors/bolt'
require 'securerandom' # UUID
require 'rexml/document'
require 'digest' # Calc SHA256 hashes
require 'os' # Get system info, esp for import. # https://github.com/rdp/os
require 'open3'
require 'active_support/core_ext/time' # To support `Time.at(unixtime).in_time_zone('America/Halifax')`
require 'active_support/core_ext/string/inflections' # pluralize / singularize
require 'rack/mime' # Convert extensions to mime-types
require 'pathname'

require 'sinatra/base'
NEO4J_URL = "bolt://#{ENV['NEO4J_CLIENT_USER']}:#{ENV['NEO4J_CLIENT_PASS']}@neo4j:7687"
NEO4J_HTTP_URL = "http://#{ENV['NEO4J_CLIENT_USER']}:#{ENV['NEO4J_CLIENT_PASS']}@neo4j:7474"

def get_session
  begin # Only move on to create a session if there is no current session (ie if Neo4j::ActiveBase.current_session throws an error)
    Neo4j::ActiveBase.current_session
    logger.debug('Session already exists, skipping CypherSession.new')
    return true
  rescue
    #neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Bolt.new(NEO4J_URL, {wrap_level: :proc, ssl:false}) #
    neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new(NEO4J_HTTP_URL, {wrap_level: :proc})
    Neo4j::ActiveBase.on_establish_session { Neo4j::Core::CypherSession.new(neo4j_adaptor) }

    return true
  end
end
class SinatraApplication < Sinatra::Base
  configure do
    ...
  end

  before do
    get_session
  end

  get '/objects/index.json' do
    return Object.all.to_json
  end
end

Runtime information:

Neo4j database version: neo4j gem version: 9.6.2 neo4j-core gem version: 9.0.0

Thanks

Joshfindit avatar May 11 '20 22:05 Joshfindit

The version 4 of Neo4j maybe doesn't work. Maybe you need see this https://github.com/neo4jrb/activegraph/issues/1607

raphox avatar Jun 08 '20 19:06 raphox