Application does not stop after AWSIotMqttClient disconnected - java

I'm working with AWSIotMqttClient to subscribe and publish to topics. After I received all messages I want to stop my application. But it works infinitely long. Here a simple code which works infinitely, even without subscribes:
SampleUtil.KeyStorePasswordPair keyStorePasswordPair =
SampleUtil.getKeyStorePasswordPair("certificate.pem", "privateKey.pem");
AWSIotMqttClient client = new AWSIotMqttClient(
"mqtt-broker.address",
"deviceID",
keyStorePasswordPair.keyStore,
keyStorePasswordPair.keyPassword);
client.connect();
client.disconnect();
Here is my logs:
> Task :Application.main()
Cert file:certificate.pem Private key: privateKey.pem
????. 20, 2019 11:56:45 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
????. 20, 2019 11:56:45 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: 5dcd561596c30e0001e4b5d5
????. 20, 2019 11:56:53 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionClosed
INFO: Connection permanently closed
????. 20, 2019 11:56:53 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionClosed
INFO: Client connection closed: 5dcd561596c30e0001e4b5d5
I can stop my application with System.exit(0) but it is undesirable for me. I expect that after all code is passed, the application will stop.

Found here . Updating aws-iot-device-sdk to 1.3.4 version
implementation 'com.amazonaws:aws-iot-device-sdk-java:1.3.4'
implementation 'com.amazonaws:aws-iot-device-sdk-java-samples:1.3.4'
resolved the problem.

Related

Couchbase N1QL query Connection failed

I'm customizing couchbase sql importer open source code in maven project.
this is my code.
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.socketConnectTimeout((int) TimeUnit.SECONDS.toMillis(45))
.connectTimeout(TimeUnit.SECONDS.toMillis(60))
.build();
cluster = CouchbaseCluster.create(env,"couchbase-dev.thisisdmg.com:8091");
bucket = cluster.openBucket(bucketName);
com.couchbase.client.java.query.Statement statement = select("*").from(i("sales_agent")).where("meta(t).id = 'appointments_appointment:1'").limit(50).offset(0);
JsonObject placeholderValues = JsonObject.create().put("age", 22);
for (N1qlQueryRow row : bucket.query(N1qlQuery.parameterized(statement, placeholderValues))) {
System.out.println(row);
}
When I send the query to server, I'm getting bellow error.
Mar 28, 2017 4:40:28 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 onSuccess
WARNING: [null][QueryEndpoint]: Could not connect to remote socket.
Mar 28, 2017 4:40:28 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 onSuccess
WARNING: [null][QueryEndpoint]: Could not connect to endpoint, retrying with delay 4096 MILLISECONDS:
com.couchbase.client.deps.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: couchbase-dev.thisisdmg.com/5.9.216.200:8093
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:257)
at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:291)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:631)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:566)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:131)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)
Please help me, how can I fix this problem.

Use Google Cloud PubSub emulator from Java

I've setup Pubsub.Builder with root url pointed to local PubSub emulator (localhost:8036 at my case). It seems to be working, I see that emulator is receiving my test pushes, but gives me error 400 Bad Request.
Publish code:
auth = GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
.createScoped(PubsubScopes.all());
client = new Pubsub.Builder(HTTP_TRANSPORT, JSON_FACTORY, auth)
.setApplicationName "test"
.setRootUrl("http://localhost:8036/")
.build();
msg = new PubsubMessage().encodeData("{\"a\": 1, \"b\": 2}".getBytes());
req = new PublishRequest().setMessages(Arrays.asList(msg));
client.projects()
.topics()
.publish("projects/GCLOUD-DEFAULT-PROJECT/topics/test-topic", req)
.execute();
In emulator console output I see following (that's for very basic PublishRequest):
[pubsub] jan 27, 2016 9:03:20 PM com.google.cloud.pubsub.testing.v1.FakePubsubGrpcServer$2 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] jan 27, 2016 9:03:20 PM com.google.cloud.pubsub.testing.v1.NettyUtil$HttpVersionDecider channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] jan 27, 2016 9:03:20 PM com.google.cloud.pubsub.testing.v1.NettyUtil$HttpJsonAdapter channelRead
[pubsub] INFO: Invalid input: Expect message object but got: "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�V�M-.NLO-V���VJI"
[pubsub] com.google.protobuf.InvalidProtocolBufferException: Expect message object but got: "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�V�M-.NLO-V���VJI"
[pubsub] at com.google.protobuf.util.JsonFormat$ParserImpl.mergeMessage(JsonFormat.java:1099)
[pubsub] at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1075)
[pubsub] at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:973)
[pubsub] at com.google.protobuf.util.JsonFormat$Parser.merge(JsonFormat.java:201)
[pubsub] at com.google.cloud.pubsub.testing.v1.PubsubJsonGrpcAdapters$PublisherAdapter.handleRequest(PubsubJsonGrpcAdapters.java:231)
[pubsub] at com.google.cloud.pubsub.testing.v1.NettyUtil$HttpJsonAdapter.channelRead(NettyUtil.java:94)
[pubsub] at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelReadNow(ChannelHandlerInvokerUtil.java:83)
Seems that default PubSub client uses different protocol, but I don't see any way to configure it.
How can I use com.google.apis:google-api-services-pubsub library with local emulator?
The emulator does not require or handle authentication or authorization; I'm guessing that's where the problem lies. Can you try passing null as the last parameter to the builder?
Also, it appears that Gzip compression must be explicitly disabled. Please set this on the builder:
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
#Override
public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
request.setDisableGZipContent(true);
}
})

Connection immediately is aborted when trying to connect to remote cluster-node

I am trying to connect to an Elasticsearch cluster form a Java application by using the TransportClient.
I have successfully tested connected to a cluster running locally.
Now we have set up a remote cluster in the EC2-Cloud. Accessing it via REST intefaces work, also Kibana works.
I can run my application on the Elasticsearch Node directly successfully.
However when I try to connect remotely from another host, the log indicates that the connection succeeds, but then immediately fails with "An established connection was aborted by the software in your host machine".
I have verified that both server and client run the same version of Elasticsearch. Also the firewall configuration should allow communication on port 9300 as this is also needed for the cluster-nodes to communicate between each other.
Okt 21, 2015 6:50:24 PM com.example.elasticsearch.visit.nativescript.ElasticsearchTest main
INFO: Setting adress to myhost.com:9300
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService addTransportAddresses
FINE: [Master Man] adding address [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
FINEST: [Master Man] connecting to listed node (light) [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport connectToNode
FINE: [Master Man] connected to node [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker addWithoutBreaking
FINEST: [Master Man] [REQUEST] Adjusted breaker by [16440] bytes, now [16440]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.TransportService$Adapter traceRequestSent
FINEST: [Master Man] [0][cluster:monitor/nodes/info] sent to [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]] (timeout: [5s])
Okt 21, 2015 6:50:24 PM org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker addWithoutBreaking
FINEST: [Master Man] [REQUEST] Adjusted breaker by [-16440] bytes, now [0]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport exceptionCaught
FINEST: [Master Man] close connection exception caught on transport layer [[id: 0xd938d867, /x.x.x.x:60058 => myhost.com/1.1.1.1:9300]], disconnecting from relevant node
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:64)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport disconnectFromNode
FINE: [Master Man] disconnecting from [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]], channel closed event
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport disconnectFromNode
FINEST: [Master Man] disconnected from [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]], channel closed event
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
INFO: [Master Man] failed to get node info for [#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[myhost.com/1.1.1.1:9300]][cluster:monitor/nodes/info] disconnected
Okt 21, 2015 6:50:24 PM com.example.elasticsearch.visit.nativescript.ElasticsearchTest main
INFO: Having: []
Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.bulk(AbstractClient.java:167)
at org.elasticsearch.client.transport.TransportClient.bulk(TransportClient.java:370)
at org.elasticsearch.action.bulk.BulkRequestBuilder.doExecute(BulkRequestBuilder.java:166)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.example.elasticsearch.visit.nativescript.ElasticsearchTest.main(ElasticsearchTest.java:68)
My simple test looks like this:
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "cluster-name")
.build();
logger.info("Creating client");
try (final TransportClient client = new TransportClient(settings)) {
logger.info("Setting adress to " + host + ":" + port);
client.addTransportAddress(new InetSocketTransportAddress(host, port));
logger.info("Having: " + client.connectedNodes());
BulkRequestBuilder bulkRequest = client.prepareBulk();
String json= "{ id: \"12345678\", value: \"value\" }";
bulkRequest.add(client.prepareIndex(INDEX, TYPE, "12345678").
setSource(json));
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
logger.info("Could not write bulk: " + bulkResponse.buildFailureMessage());
} else {
logger.info("Wrote");
}
}
I also tried to verify some common things like cluster-name not set and others.
Also when I use a completely different port, I get a timeout as expected, not this error-message. So the port is definitely behaving different.
Where would I start to look? Can this still be a firewall issue where connections are dropped only after a short while instead of being rejected immediately?
With more testing I actually found out that a company-firewall was interfering in a strange way. When I run the same client-code on a machine outside the company-netowrk, it works fine.

MongoDB SDK Failover not working

I have set up a replica set using three machines (192.168.122.21, 192.168.122.147 and 192.168.122.148) and I am interacting with the MongoDB Cluster using the Java SDK:
ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
addrs.add(new ServerAddress("192.168.122.21", 27017));
addrs.add(new ServerAddress("192.168.122.147", 27017));
addrs.add(new ServerAddress("192.168.122.148", 27017));
this.mongoClient = new MongoClient(addrs);
this.db = this.mongoClient.getDB(this.db_name);
this.collection = this.db.getCollection(this.collection_name);
After the connection is established I do multiple inserts of a simple test document:
for (int i = 0; i < this.inserts; i++) {
try {
this.collection.insert(new BasicDBObject(String.valueOf(i), "test"));
} catch (Exception e) {
System.out.println("Error on inserting element: " + i);
e.printStackTrace();
}
}
When simulating a node crash of the master server (power-off), the MongoDB cluster does a successful failover:
19:08:03.907+0100 [rsHealthPoll] replSet info 192.168.122.21:27017 is down (or slow to respond):
19:08:03.907+0100 [rsHealthPoll] replSet member 192.168.122.21:27017 is now in state DOWN
19:08:04.153+0100 [rsMgr] replSet info electSelf 1
19:08:04.154+0100 [rsMgr] replSet couldn't elect self, only received -9999 votes
19:08:05.648+0100 [conn15] replSet info voting yea for 192.168.122.148:27017 (2)
19:08:10.681+0100 [rsMgr] replSet not trying to elect self as responded yea to someone else recently
19:08:10.910+0100 [rsHealthPoll] replset info 192.168.122.21:27017 heartbeat failed, retrying
19:08:16.394+0100 [rsMgr] replSet not trying to elect self as responded yea to someone else recently
19:08:22.876+.
19:08:22.912+0100 [rsHealthPoll] replset info 192.168.122.21:27017 heartbeat failed, retrying
19:08:23.623+0100 [SyncSourceFeedbackThread] replset setting syncSourceFeedback to 192.168.122.148:27017
19:08:23.917+0100 [rsHealthPoll] replSet member 192.168.122.148:27017 is now in state PRIMARY
This is also recognized by the MongoDB Driver on the Client Side:
Dec 01, 2014 7:08:16 PM com.mongodb.ConnectionStatus$UpdatableNode update
WARNING: Server seen down: /192.168.122.21:27017 - java.io.IOException - message: Read timed out
WARNING: Server seen down: /192.168.122.21:27017 - java.io.IOException - message: couldn't connect to [/192.168.122.21:27017] bc:java.net.SocketTimeoutException: connect timed out
Dec 01, 2014 7:08:36 PM com.mongodb.DBTCPConnector setMasterAddress
WARNING: Primary switching from /192.168.122.21:27017 to /192.168.122.148:27017
But it still keeps trying to connect to the old node (forever):
Dec 01, 2014 7:08:50 PM com.mongodb.ConnectionStatus$UpdatableNode update
WARNING: Server seen down: /192.168.122.21:27017 - java.io.IOException - message: couldn't connect to [/192.168.122.21:27017] bc:java.net.NoRouteToHostException: No route to host
.....
Dec 01, 2014 7:10:43 PM com.mongodb.ConnectionStatus$UpdatableNode update
WARNING: Server seen down: /192.168.122.21:27017 - java.io.IOException -message: couldn't connect to [/192.168.122.21:27017] bc:java.net.NoRouteToHostException: No route to host
The Document count on the Database stays the same from the moment the primary fails and a secondary becomes primary. Here is the Output from the same node during the process:
"rs0":SECONDARY> db.test_collection.find().count() 12260161
"rs0":PRIMARY> db.test_collection.find().count() 12260161
Update:
Using WriteConcern Unacknowledged it works as designed. Insert Operations are also performed on the new master and all operations during the election process get lost.
With WriteConcern Acknowleged it seems that the Operation is waiting infinitely for an ACK from the crashed master. This could explain why the program continuous after the crashed server boots up again and joins the cluster as a secondary. But in my case I don't want the driver to wait forever, it should raise an error after a certain time.
Update:
WriteConcern Acknowledged is also working as expected when killing the mongod process on the primary. In this case the failover only takes ~3 Seconds. During this time no inserts are done, and after the new primary is elected the insert operations continue.
So I only get the problem when simulating a node failure (power off/network down). In this case the operation hangs until the failed node starts up again.
Does your app still work? Since that server is still in your seed list, the driver will try to connect to it as far as I know. Your app should still work so long as any of the other servers in your seed list can gain primary status.
Explicit specifying a Connection Timeout Value solved the error. See also: http://api.mongodb.org/java/2.7.0/com/mongodb/MongoOptions.html

Issue with JacORB connection?

I'm new to CORBA and JacORB. I'm struggling with my first Hello World app using CORBA with JacORB.
This is the newest error I got:
Nov 04, 2013 9:52:19 AM com.sun.corba.se.impl.transport.SocketOrChannelConnectionIm <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 7070"
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
This is my server causes to that error:
Properties props = new Properties();
props.put("org.omg.CORBA.ORBInitialPort","7070");
props.put("org.omg.CORBA.ORBInitialHost","localhost");
ORB orb = ORB.init(args, props);
try {
//
POA poa = POAHelper.narrow(orb
.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
// Servant
HelloVnImpl hello = new HelloVnImpl();
// get servant reference
Object o = poa.servant_to_reference(hello);
HelloVn hVnRef = HelloVnHelper.narrow(o);
// Get root naming context
Object objRef = orb.resolve_initial_references("NameService");//Error
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
Look around on the internet, the issue is apparently my nameservice, but I think I start it.
C:\Users\Paul>ns -ORBInitRef.NameService=corbaloc::localhost:7070/NameService
Nov 04, 2013 9:38:25 AM org.jacorb.config.JacORBConfiguration <init>
WARNING: no properties found for configuration jacorb
Nov 04, 2013 9:38:25 AM org.jacorb.orb.ORBSingleton <init>
INFO: created ORBSingleton
Nov 04, 2013 9:38:27 AM org.jacorb.orb.giop.CodeSet getTCSDefault
WARNING: Warning - unknown codeset (Cp1252) - defaulting to ISO-8859-1
Nov 04, 2013 9:38:27 AM org.jacorb.naming.NameServer main
INFO: NS up
Nov 04, 2013 9:38:27 AM org.jacorb.orb.ORB run
INFO: ORB run
Now, I have no idea to do next. Please give me an advice. Thank you. :)
UPDATE:
This line code give me a null value:
System.out.println(System.getProperty("org.omg.CORBA.ORBClass"));
What does it mean?. Does it tell me that there is something wrong with my nameserver?.
Hope to see your advice. Thanks
There are a couple of problems with the way that you setup your server and the Naming Service (NS):
1) The two properties (org.omg.CORBA.ORBInitialPort and org.omg.CORBA.ORBInitialHost) that you set in the server code are not JacORB properties. Assuming that you want your server to listen for requests on port 7070,then you want to set the "OAAddress" property like this:
props.put("OAAdress", "iiop://localhost:7070");
2) The option -ORBInitRef.NameService=corbaloc::localhost:XXX/NameService should be for the server to locate the NS and is not the NS. Please note that "XXX" is the listen port of the NS and is should not be "7070".
I would recommend that you take a look at the hello demo which includes both a working server and client and they are much simpler.

Categories

Resources