cant connect from my desktop to rabbitmq on ec2 - java

I am trying to create an ubuntu vm with rabbitmq on EC2.
I can telnet my rabbit but cant connect with java client.
Here is my code
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("172.31.4.61");
factory.setPort(5672);
Connection connection = factory.newConnection();
I get the following
java.net.ConnectException: Connection timed out: connect
Any ideas?

Make sure you add a rule to allow inbound traffic for port 5672 in the EC2 Security Group.

Related

How to setup Java RMI RMI connection between docker containers in different hosts

I have the a docker container (Name CON1) running in the host A, this container is a java RMI server listening on port 1099. I also have another the container (Name CON2) running a java RMI client in the host B. When I telnet CON1 from CON2 using the RMI port 1099 it works fine:
$ telnet 172.30.34.74 1099
Trying 172.30.34.74...
Connected to 172.30.34.74.
Escape character is '^]'.
But when I try to connect through the java RMI client the connection is refused and the error message shows a different IP address for CON1.
java.rmi.ConnectException: Connection refused to host: 172.18.0.2; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)
Although I use 172.30.34.74 to make the lookop in the RMI client code, the error message shows other IP address (172.18.0.2). When I run the RMI server and the RMI client outside a docker container it works good.
What can I check to solve this situation?
I implemented a solution:
Add to the java command line to start the RMI server the argument -Djava.rmi.server.hostname=HOST_IP. Where host HOST_IP is the host IP.
Set the container's network_mode to host. This way, the container would take same IP as host.

Connecting to Amazon ElastiCache using Java Redis client (Lettuce)

. . it is possible to connect to Amazon Elastic Cache from my local machine with a java redis client (lettuce) ?
I have defined Inbound rules in the Security Group to TCP port 6379 and SSH port 22 to any IP address.
my connecting code is:
RedisClient redisClient = new RedisClient("CacheCluster Endpoint", 6379);
RedisConnection<String, String> connection = redisClient.connect();
connection.set("key", "Hello, Redis!");
connection.close();
redisClient.shutdown();
I run this java and I got:
Exception in thread "main" com.lambdaworks.redis.RedisConnectionException: Unable to connect to mycachecluster.b4ujee.0001.usw2.cache.amazonaws.com/172.31.34.211:6379
at com.lambdaworks.redis.AbstractRedisClient.initializeChannel(AbstractRedisClient.java:214)
at com.lambdaworks.redis.RedisClient.connectAsync(RedisClient.java:322)
at com.lambdaworks.redis.RedisClient.connectAsync(RedisClient.java:303)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:259)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:238)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:222)
at project1.JavaRedis.main(JavaRedis.java:17)
Caused by: java.net.ConnectException: Connection timed out: no further information: mycachecluster.b4ujee.0001.usw2.cache.amazonaws.com/172.31.34.211:6379
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:224)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:289)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:619)
so my question is: What am I doing so wrong ? have I to use the ClusterRedis EndPoint or EC2 DNS to stablished the connection ?
help please !!!
THANKS!!!
No, you can't connect to it because it doesn't have a public IP. The DNS name resolves into a private IP, 172.31.34.211, which can only be accessed from your AWS VPC.
Also, for connecting you need to use the DNS, not the IP, because the IP of the node might change.
If you need to develop locally with Redis, you can easily install one instance on your local machine.
The best way to do this, if you still want to connect from your local to AWS ElastiCache (redis) without hosting your web service in AWS, is through a VPN.
We are using https://pritunl.com for this, it is very easy to configure and use.

Connection String of MS-SQL to put in JAVA

What should be the connection string for MSSQL Database in JAVA? Something like this.
Like someother things I want to know that Is there any password in connection string like password of my computer? what should be the port number, url etc? If you need more information about the connection let me know.
P.S. The black line has the servername.
My Connection values
datasource.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
datasource.url=jdbc:sqlserver://MSSQLSERVERFULL;databaseName=xproctor;
datasource.user=JUNAID-VAIO\Shamim
datasource.password=
ERROR:
here is the ERROR I get while trying to connect database!!
Error querying database. Cause:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not
get JDBC Connection; nested exception is
org.apache.commons.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (The TCP/IP connection to the host
MSSQLSERVERFULL, port 1433 has failed. Error: "null. Verify the
connection properties. Make sure that an instance of SQL Server is
running on the host and accepting TCP/IP connections at the port. Make
sure that TCP connections to the port are not blocked by a
firewall.".)
Use this connection string:
jdbc:sqlserver://;servername=server_name;integratedSecurity=true;authenticationScheme=JavaKerberos
The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect".
Enable Name pipes, TCP/IP, change Authentication mode, change localhost to 127.0.0.1 or .,
add the Instance Name to the url, change the port, enable port and Apps in the firewall... almost everything.
Its horrible! But the answer for your problem is: open SQL Server Configuration Manager -> Protocols for SQL SQLEXPRESS, select Properties of TCP/IP. In the tab IP Addresses, set the TCPPort in section IPAll to 1433.

Can't connect two remote hosts in Java RMI

My server's code looks like:
Registry r = java.rmi.registry.LocateRegistry.createRegistry(1399);
r.rebind("Chat", new IRC());
and my client's code is
IRCInterface remoteObject = (IRCInterface) Naming.lookup("rmi://localhost:1399/Chat");
String history = remoteObject.read();
on the localhost it works correctly, but I can't connect two remote computers (hosts).
I've turned off all firewalls.
What's wrong?
The console outputs:
Error: java.rmi.ConnectException: Connection refused to host: 150.254.79.20; nested exception is:
java.net.ConnectException: Connection timed out: connect
Naming.lookup("rmi://localhost:1399/Chat");
localhost in above lookup should be replaced with remotehost IP (or) machine name. Otherwise lookup happens on only local machine.

Unable to connect to ftp server java

I should be able to successfully send and receive file to/from FTP server.
But then, no changes occurred in the code and I started getting this :
Error: java.net.ConnectException: Connection timed out: connect
What I am doing is:
FTPClient ftp = new FTPClient();
ftp.connect( IPADDRESS of FTP server);
connect() is giving this execption. I am not understanding the cause for it.
The error message is telling you that the OS's attempt to connect to the server timed out. This typically means that:
the remote server has dropped off the network, or
something (e.g. a firewall) is "black holing" packets sent to the server on the FTP port.
Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port).
Source: JavaDoc.

Categories

Resources