Last active
June 27, 2017 21:21
-
-
Save ingenthr/af9a410dcb5db6ff0256d4205fb7a7dc to your computer and use it in GitHub Desktop.
Example of Couchbase Client and logback for seeing stuff with connections.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java -Dvisualvm.id=143219730683802 -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/ingenthr/src/testproject/target/classes:/Users/ingenthr/.m2/repository/com/couchbase/client/java-client/2.4.6/java-client-2.4.6.jar:/Users/ingenthr/.m2/repository/com/couchbase/client/core-io/1.4.6/core-io-1.4.6.jar:/Users/ingenthr/.m2/repository/io/reactivex/rxjava/1.2.7/rxjava-1.2.7.jar:/Users/ingenthr/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar:/Users/ingenthr/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar:/Users/ingenthr/.m2/repository/org/slf4j/slf4j-api/1.7.6/slf4j-api-1.7.6.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.couchbase.client.demo.Example | |
14:18:32.887 [main] INFO c.c.client.core.CouchbaseCore - CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword=false, sslKeystore=null, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=8, computationPoolSize=5, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=12, queryServiceEndpoints=12, searchServiceEndpoints=12, configPollInterval=2500, ioPool=NioEventLoopGroup, kvIoPool=null, viewIoPool=null, searchIoPool=null, queryIoPool=null, coreScheduler=CoreScheduler, memcachedHashingStrategy=DefaultMemcachedHashingStrategy, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.4.6 (git: 2.4.6, core: 1.4.6), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=true, socketConnectTimeout=1000, dcpConnectionBufferSize=20971520, dcpConnectionBufferAckThreshold=0.2, dcpConnectionName=dcp/core-io, callbacksOnIoPool=false, disconnectTimeout=25000, requestBufferWaitStrategy=com.couchbase.client.core.env.DefaultCoreEnvironment$2@307f6b8c, queryTimeout=75000, viewTimeout=75000, searchTimeout=75000, analyticsTimeout=75000, kvTimeout=2500, connectTimeout=5000, dnsSrvEnabled=false} | |
14:18:32.961 [main] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Got instructed to connect. | |
14:18:32.964 [cb-computations-1] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service BINARY | |
14:18:32.968 [cb-computations-1] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service BINARY to registry and connecting it. | |
14:18:33.388 [cb-io-1-1] INFO com.couchbase.client.core.node.Node - Connected to Node 127.0.0.1/localhost | |
14:18:33.388 [cb-io-1-1] DEBUG com.couchbase.client.core.node.Node - Connected (CONNECTING) to Node NetworkAddress{localhost/127.0.0.1, fromHostname=false, reverseDns=true} | |
14:18:33.498 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service QUERY | |
14:18:33.500 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service QUERY to registry and connecting it. | |
14:18:33.500 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service VIEW | |
14:18:33.501 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service VIEW to registry and connecting it. | |
14:18:33.501 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service SEARCH | |
14:18:33.502 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service SEARCH to registry and connecting it. | |
14:18:33.502 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service BINARY | |
14:18:33.502 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service BINARY already added, skipping. | |
14:18:33.502 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service CONFIG | |
14:18:33.503 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service CONFIG to registry and connecting it. | |
14:18:33.505 [cb-computations-4] INFO c.c.c.c.config.ConfigurationProvider - Opened bucket travel-sample | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service QUERY | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service QUERY already added, skipping. | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service VIEW | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service VIEW already added, skipping. | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service SEARCH | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service SEARCH already added, skipping. | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service BINARY | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service BINARY already added, skipping. | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Adding Service CONFIG | |
14:18:33.505 [cb-computations-4] DEBUG com.couchbase.client.core.node.Node - [127.0.0.1/localhost]: Service CONFIG already added, skipping. | |
Process finished with exit code 130 (interrupted by signal 2: SIGINT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.couchbase.client.demo; | |
import com.couchbase.client.core.metrics.DefaultLatencyMetricsCollectorConfig; | |
import com.couchbase.client.core.metrics.DefaultMetricsCollectorConfig; | |
import com.couchbase.client.java.*; | |
import com.couchbase.client.java.document.*; | |
import com.couchbase.client.java.document.json.*; | |
import com.couchbase.client.java.env.CouchbaseEnvironment; | |
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; | |
import com.couchbase.client.java.query.*; | |
import com.couchbase.client.java.query.core.N1qlQueryExecutor; | |
import com.couchbase.client.java.query.dsl.Expression; | |
import java.util.concurrent.TimeUnit; | |
import static com.couchbase.client.java.query.Select.select; | |
import static com.couchbase.client.java.query.dsl.Expression.i; | |
import static com.couchbase.client.java.query.dsl.Expression.x; | |
public class Example { | |
public static void main(String... args) throws Exception { | |
CouchbaseEnvironment env = (CouchbaseEnvironment) DefaultCouchbaseEnvironment | |
.builder() | |
.mutationTokensEnabled(true) | |
.computationPoolSize(5) | |
.configPollInterval(2500) | |
.build(); | |
Cluster cluster = CouchbaseCluster.create(env, "localhost"); | |
// Initialize the Connection | |
// Cluster cluster = CouchbaseCluster.create("centos7lx-1"); | |
cluster.authenticate("travel-sample", "travel-sample"); // this is for 5.0 style RBAC auth | |
Bucket bucket = cluster.openBucket("travel-sample"); | |
// | |
// // Create a JSON Document | |
// JsonObject arthur = JsonObject.create() | |
// .put("name", "Arthur") | |
// .put("email", "kingarthur@couchbase.com") | |
// .put("interests", JsonArray.from("Holy Grail", "African Swallows")); | |
// | |
// // Store the Document | |
// bucket.upsert(JsonDocument.create("u:king_arthur", arthur)); | |
// | |
// // Load the Document and print it | |
// // Prints Content and Metadata of the stored Document | |
// System.out.println(bucket.get("u:king_arthur")); | |
// | |
// Create a N1QL Primary Index (but ignore if it exists) | |
bucket.bucketManager().createN1qlPrimaryIndex(true, false); | |
System.setProperty(N1qlQueryExecutor.ENCODED_PLAN_ENABLED_PROPERTY, "false"); | |
String bucketName = "travel-sample"; | |
// Expression expression = x("sample_id").eq(x("$sample_id")); | |
// String selectStatement = "count(*) as size"; | |
// Statement statement= select(selectStatement) | |
// .from(i(bucketName)) | |
// .where(expression) | |
// .limit(20); | |
// JsonObject placeHolderValues = JsonObject.create().put("sample_id", 1); | |
// N1qlParams params = N1qlParams.build().adhoc(false); | |
// ParameterizedN1qlQuery query = N1qlQuery | |
// .parameterized(statement, placeHolderValues, params); | |
// | |
// System.err.println(query); | |
// bucket.query(query); | |
String scanAllQuery = "SELECT RAW meta().id FROM `" + bucketName + | |
"` WHERE meta().id >= '$1' ORDER BY meta().id LIMIT $2"; | |
// "` WHERE meta().id >= $1 ORDER BY meta().id LIMIT $2"; | |
ParameterizedN1qlQuery query1 = N1qlQuery.parameterized(scanAllQuery, JsonArray.create().add("airline_20").add(10)); | |
N1qlQueryResult result = bucket.query(query1); | |
// // Perform a N1QL Query | |
// N1qlQueryResult result2 = bucket.query( | |
// N1qlQuery.simple("SELECT * FROM default", params)); | |
// // Perform a N1QL Query | |
// N1qlQueryResult result = bucket.query( | |
// N1qlQuery.simple("SELECT * FROM system:prepareds")); | |
System.err.println(query1); | |
// Print each found Row | |
for (N1qlQueryRow row : result) { | |
// Prints {"name":"Arthur"} | |
System.out.println(row); | |
} | |
System.err.println(result); | |
} | |
public static void setUp() throws InterruptedException { | |
DefaultCouchbaseEnvironment environment = DefaultCouchbaseEnvironment.builder() | |
.networkLatencyMetricsCollectorConfig(DefaultLatencyMetricsCollectorConfig.builder() | |
.emitFrequency(10) | |
.emitFrequencyUnit(TimeUnit.SECONDS) | |
.build()) | |
// .runtimeMetricsCollectorConfig(DefaultMetricsCollectorConfig) | |
.connectTimeout(30000) | |
.queryTimeout(75000) | |
.queryEndpoints(10) | |
.kvTimeout(10000) | |
.build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
<encoder> | |
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
</encoder> | |
</appender> | |
<logger name="com.couchbase.client.core.node" level="debug" /> | |
<root level="info"> | |
<appender-ref ref="STDOUT" /> | |
</root> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.couchbase.client.demo</groupId> | |
<artifactId>testproject</artifactId> | |
<version>0.1-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>com.couchbase.client</groupId> | |
<artifactId>java-client</artifactId> | |
<version>2.4.6</version> | |
</dependency> | |
<dependency> | |
<groupId>ch.qos.logback</groupId> | |
<artifactId>logback-classic</artifactId> | |
<version>1.1.2</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment