How to use bolt protocol to access my Neo4j Database? - neo4j

I am new to Neo4j and am reading this example:
try ( HelloWorldExample greeter = new HelloWorldExample( "bolt://localhost:7687", "neo4j", "test" ) )
{
greeter.printGreeting( "hello, world" );
}
In my Eclipse, this code works fine. However, I already have a Neo4j database which I can access through
http://localhost:7474/browser/
My question is in my Java code above, how can I access my existing Neo4j database? If I change "bolt://localhost:7687" to "http://localhost:7474", I received this error:
Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: Unsupported URI scheme: http
at org.neo4j.driver.internal.DriverFactory.createDriver(DriverFactory.java:125)
at org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:82)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:136)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:119)
at org.neo4j.driver.v1.GraphDatabase.driver(GraphDatabase.java:94)
at neo4j.Neo4j.<init>(Neo4j.java:19)
at neo4j.Neo4j.main(Neo4j.java:50)
So how can I access my existing database (http://localhost:7474) through 'bolt'?

You can access a Neo4j database through 2 protocols :
HTTP/REST on default port 7474
BOLT on default port 7687
So on your example, you are trying to use a BOLT client on the HTTP, this can't work.
So the good url is the one into your java code : "bolt://localhost:7687"

Related

How to visualize remote neo4j auradb with neovis.js?

I have a remote AuraDB, but I'm unable to visualize with neovis.js
var config = {
container_id: "viz",
server_url: "bolt://<server_url>:7687",
server_user: <user>,
server_password: <pwd>,
initial_cypher: "match n=(:Person)-[:Knows]->(:Person) return n"
}
The above code segment is from the neovis GitHub documentation.
(https://github.com/neo4j-contrib/neovis.js/)
If I use the "bolt" protocol, the error is :
Neo4jError: WebSocket connection failure. Due to security constraints in your web browser, the reason for the failure is not available to this Neo4j Driver. Please use your browsers development console to determine the root cause of the failure. Common reasons include the database being unavailable, using the wrong connection URL or temporary network problems. If you have enabled encryption, ensure your browser is configured to trust the certificate Neo4j is configured to use. WebSocket readyState is: 3
If I use the "neo4j" protocol, then :
Neo4jError: Could not perform discovery. No routing servers available.
If I use the "neo4j+s" / "neo4j+ssc" protocols, then :
Encryption/trust can only be configured either through URL or config, not both
I have observed neovis plugin for my webapp works well with a local neo4j db and the bolt protocol.
Please help me out with some understanding in the case of visualizing a remote neo4j aura db.
Aura has strict encryption policies. And the driver config used for neovis.js seems half-baked. It doesn't seem to be enough for Aura and doesn't seem to allow turning encryption off completely either.
So the best option here is to enforce encryption in the config and use an unencrypted connection Scheme.
Working config for Aura by using an unencrypted connection URI and enforcing encryption in the config
var config = {
encrypted:"ENCRYPTION_ON",
trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
container_id: "viz",
server_url: "neo4j://<dbid>.databases.neo4j.io",
...
Updated Solution for Neovis 2.0.2, from this GitHub issue
var config = {
containerId: "viz",
neo4j: {
serverUrl: "neo4j://<dbid>.databases.neo4j.io",
serverUser: "neo4j",
serverPassword: "secret",
driverConfig: {
encrypted: "ENCRYPTION_ON",
trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES"
}
},

Posting byte message in solace queue through jmeter

Need to post a byte message to solace queue using Jmeter. I have tried in following manner might be am incorrect but tried with following:
Use JMSPublisher sampler
create jndi.properties file and put in jmeter/lib
jndi.properties
java.naming.factory.initial = com.solacesystems.jndi.SolJNDIInitialContextFactory
java.naming.provider.url = smf://<remote IP and port>
java.naming.security.principal=<username>
java.naming.security.credentials=<password>
Solace_JMS_VPN=<VPN Name>
in JMSPublisher sampler (in GUI)
Connection Factory = connectionFactory
Destination = (Queue Name )
Message Type (radio button---Byte message)
Content encoding -- RAW
in text area ---> (Byte message)
Note : I have used actual values of IP/port/username/port/queuename/bytemessage, cannot share those. Soljms jar is available in lib folder too.
getting error :
Response message: javax.naming.NamingException: JNDI lookup failed - 503: Service Unavailable [Root exception is (null) com.solacesystems.jcsmp.JCSMPErrorResponseException: 503: Service Unavailable]
Though it is working perfectly fine when did with java spring boot. There used properties files in place of JNDI.
It would be great if anyone can guide me , please do not give activeMQ JNDI am actively looking for posting on solace queue or create connection to solace appliances through Jmeter.
I don't think you should be putting your Byte message into the textarea as it accepts either plain text or an XStream object, consider providing your payload via binary file(s) instead
If you're capable of sending the message using Java code you should be able to replicate the same using:
JMeter's JSR223 Sampler with Groovy language (Java syntax will work)
Or JUnit Request sampler if you need "strict" java

Docker - URL syntax [duplicate]

What is the format for the PostgreSQL connection string (URL postgres://...) when the host is not the localhost?
If you use Libpq binding for respective language, according to its documentation URI is formed as follows:
postgresql://[user[:password]#][netloc][:port][/dbname][?param1=value1&...]
Here are examples from same document
postgresql://
postgresql://localhost
postgresql://localhost:5432
postgresql://localhost/mydb
postgresql://user#localhost
postgresql://user:secret#localhost
postgresql://other#localhost/otherdb?connect_timeout=10&application_name=myapp
postgresql://localhost/mydb?user=other&password=secret
The following worked for me
const conString = "postgres://YourUserName:YourPassword#YourHostname:5432/YourDatabaseName";
DATABASE_URL=postgres://{user}:{password}#{hostname}:{port}/{database-name}
Here is the documentation for JDBC, the general URL is "jdbc:postgresql://host:port/database"
Chapter 3 here documents the ADO.NET connection string,
the general connection string is Server=host;Port=5432;User Id=username;Password=secret;Database=databasename;
PHP documentation us here, the general connection string is
host=hostname port=5432 dbname=databasename user=username password=secret
If you're using something else, you'll have to tell us.
the connection url for postgres
syntax:
"Server=host ipaddress;Port=5432;Database=dbname;User Id=userid;Password=password;
example:
"Server=192.168.1.163;Port=5432;Database=postgres;User Id=postgres;Password=root;
server.address=10.20.20.10
server.port=8080
database.user=username
database.password=password
spring.datasource.url=jdbc:postgresql://${server.address}/${server.port}?user=${database.user}&password=${database.password}
The connection string can also be retrieved programmatically from working DB connectors.
For instance I sometimes extract connection strings from SQLAlchemy's engine, like this:
> db_engine.url
postgres://{user}:{password}#{host}:{port}/{db_name}?sslmode=require
Some people seem to misread the database name as a server name and the host as a postgresql server? A host hosts a postgresql server that has a database. Or am I missing something.
postgresql://my_host/&server=my_postgresql_server?user=my_user&port=my_port&password=my_password&database=my_database
Example:
my_host: can be "localhost" (but that is not in the question) or an ip address of a host.
postgresql://my_host/&server=postgres?user=postgres&port=5432&password=postgres&database=test_db
Worked for me in Python with sqlalchemy and a postgresql localhost running. Needs sqlalchemy, postgresql, and psycopg2 to get it to work.
PS: The question is about a postgres://... URL, but this would not work here. Instead, you need postgresql, and what is run in the end in Python is dialect+driver (see Database URLs) = postgresql+psycopg2, without having to write it like this.
The general format of database url
DATABASE_URL=postgresql://username:password#host:port/dtabase_name
If you are using postgresql sql with asyncpg the database url would be
DATABASE_URL=postgresql+asyncpg://username:password#host:port/dtabase_name
Remember to never push your database password so you should use your DATABASE_URL in .env file
The port is optional if you use the default one
Like this you can connect both local and remote database think of that once you want to check an issue that occur in the remote deployed versions
ex of localhost DATABASE_URL would be
DATABASE_URL=postgresql+asyncpg://postgres:dina#localhost/mysens
If you deployed your database on Heroku and you want to connect it with your local app, go to Heroku Postgres installed add-on go to settings and click on view credential in Database Credentials and use the uri to connect to your database
DATABASE_URL=postgresql+asyncpg://sqnalxxxxxxxxx:160xxxx2bdd2942b26c93c392xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#ec2-35-173-91-114.compute-1.amazonaws.com:5432/del6o4cjoqfsov

Getting IP Address current server

I used symfony 1.4 to create my application.
I'd like to get the IP adress of the current server to put it within soap request
So, how can i get the IP address of the current server?
For most situations, using $_SERVER['SERVER_ADDR']; will work. If that doesn't work you can try $ip = gethostbyname(gethostname());
If you have access to the $request object and it is a sfWebRequest (typical request from a browser) you can use:
$request->getPathInfoArray()['SERVER_ADDR']
Premise of the following method: your domain name has only one IP resolution
Using PHP:
gethostbyname($_SERVER['SERVER_NAME'])
$_SERVER['SERVER_NAME']will generally return your domain name (server_name / ServerName is configured in Nginx / Apache server), and then use gethostbyname().
About $_SERVER['SERVER_ADDR'], it often return a LAN IP address (I only have one server, one domain name, no reverse proxy; cloud server).
About gethostname()
In the test, it returns the name of the server (host name, not the domain name you use), and then uses gethostbyname(), will return a LAN IP.
More can be used https://checkip.amazonaws.com/ Get the current IP.

Graphstory and Neo4jphp

I have succesfully used neo4jphp library with graphenedb with this simple steps as per documentation (considering that graphenedb does not require https)
require('vendor/autoload.php'); // or your custom autoloader
// Connecting to a different port or host
$client = new Everyman\Neo4j\Client(url, port);
// Connecting using HTTP and Basic Auth
$client->getTransport()
->setAuth('username', 'password');
// Test connection to server
print_r($client->getServerInfo());
However, when trying to connect to a graphstory instance (of course they both work fine if I call the rest api from browser, the neo4j console works fine etc.) which requires https as follows
require('vendor/autoload.php'); // or your custom autoloader
// Connecting to a different port or host
$client = new Everyman\Neo4j\Client(url, port);
// Connecting using HTTPS and Basic Auth
$client->getTransport()
->useHttps()
->setAuth('username', 'password');
// Test connection to server
print_r($client->getServerInfo());
I get the following error. They should be identical, I can't get why.
Fatal error: Uncaught exception 'Everyman\Neo4j\Exception' with message 'Can't open connection to https://neo-54f500bf2cc7e-364459c455.do-stories.graphstory.com:7473/db/data/' in /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Transport/Curl.php:91
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Transport.php(95): Everyman\Neo4j\Transport\Curl->makeRequest('GET', '/', NULL)
#1 /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Command.php(64): Everyman\Neo4j\Transport->get('/', NULL)
#2 /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Client.php(828): Everyman\Neo4j\Command->execute()
#3 /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Client.php(464): Everyman\Neo4j\Client->runCommand(Object(Everyman\Neo4j\Command\GetServerInfo))
#4 /Applications/XAMPP/xamppfiles/htdocs/graphene/story.php(20): Every in /Applications/XAMPP/xamppfiles/htdocs/graphene/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Transport/Curl.php on line 91
It seems to me that neo4jphp is not configuring the TLS part in the cURL request.
I fixed it by downloading the certificate bundle from http://curl.haxx.se/docs/caextract.html (ca_bundle.crt) and adding the following line to Everyman\Neo4j\Transport\Curl.php, function makeRequest:
$options[CURLOPT_CAINFO] = "your/path/to/ca-bundle.crt";
I've created an issue on GitHub for this: https://github.com/jadell/neo4jphp/issues/171
I'm the CTO/Lead Dev at Graph Story. Sorry to hear you're having troubles. I've actually just taken a look at your instance and things seem OK from the server side.
Without additional info it's hard to say if there's an issue with your sample connection code. Considering that you've used that same library to connect to GrapheneDB in the past, I think the chances an error in the sample code is low.
Based on the current state of your instance and on the exception thrown by Neo4jPHP, my guess is that port 7473 may be blocked on your network. You can confirm that with local tech support or by switching to a network where you know port 7473 is open and trying to connect again.

Resources