RabbitMQ tutorials code not working - rabbitmq

I am in the process of learning RabbitMQ. I started with the basic rabbitmq tutorials in their website, unfortunately I am not able to compile them due to the following errors:
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Error: "The method newConnection(Address[]) in the type ConnectionFactory is not applicable for the arguments ()"
Connection connection = factory.newConnection();
Error: The method newConnection(Address[]) in the type ConnectionFactory is not applicable for the arguments ()
The maven dependency I have is:
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>rabbitmq-client</artifactId>
<version>0.9.1</version>
</dependency>
What exactly am I doing wrong here? Any help would be appreciated!
Thanks!

Your tutorial seems to be "old", try out a more up to date version. The current release of the RabbitMQ Java AMQP library is 3.1.3.. But also have a look at the Maven Repository. Try out version 3.1.1, it's the newest version in the mvn repo.
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.1.1</version>
</dependency>

Related

java.lang.NoSuchFieldError: Companion when using okhttp3 and selenium

I'm using Retrofit2 and Okhttp to make HTTP calls in my project, that also uses Selenium. As soon as I added the following dependency:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.9.0</version>
</dependency>
I started to see the following error:
java.lang.NoSuchFieldError: Companion
at okhttp3.logging.HttpLoggingInterceptor$Logger$Companion$DefaultLogger.log(HttpLoggingInterceptor.kt:116)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:168)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
I have checked some related issues and everything points to a dependency problem. However, I'm using the latest versions for Okhttp and Retrofit2 (2.9.0), as well as for selenium-java:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
What I'm trying to do is just to log a simple request using:
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(url)
.client(httpClient.build())
.build();
Do you know what could be the issue?
I'm using the latest Kotlin plugin in IntelliJ
It's most likely a dependency problem. See which JARs are imported in your IDE then debug the error. Otherwise make a simple standalone android project to run this code. You can also use the okhttp bom to upgrade cleanly to 4.9.0.
https://github.com/square/okhttp#releases
dependencies {
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
}

ERROR FIREFOX IN SELENIUM 3

[i have added gecko driver to system.set property, but still its not launching]
java.lang.NoSuchMethodError: org.openqa.selenium.net.PortProber.waitForPortUp(IILjava/util/concurrent/TimeUnit;)V
I was getting the same error. When I debug my application, I found that it was referring the old Selenium jar. To resolve this, I removed the old jar's and rebuild the project with Selenium 3 jars.
Ensure that you have right libraries added to your project.
Hope this helps.
In my case I got similar issue when I added dependency to phantomdriver to my project pom. Selenium 3.0 got it own dependency to phantomdriver already, which produced dependency conflict and not allows to geckodriver to be started. Solution was to remove additional dependency to phantomdriver.
Hridesh Gupta & user3153853, guys, your answers helped me A LOT! Thanks!
So I had the same issue, FF was not launching returning an exception:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
...
enter code hereCaused by: java.lang.NoSuchMethodError: org.openqa.selenium.net.PortProber.waitForPortUp(IILjava/util/concurrent/TimeUnit;)
...
It turned out the same thing - dependencies collision.
I had:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
and I added this:
<dependency>
<groupId>ru.yandex.qatools.ashot</groupId>
<artifactId>ashot</artifactId>
<version>1.5.3</version>
</dependency>
Apparently,
<version>1.5.3</version>
was not compatible with
<version>3.0.1</version>
so by reducing Ashot's version down to
<version>1.5.2</version>
I fixed FF issue.

Apache Curator Unimplemented Errors When Trying to Create zNodes

I'm attempting to use Apache Curator with a dockerized zookeeper instance and no matter how I attempt to connect I always end up with a
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for...
error. I've tried making sense of the documentation but I'm not getting anywhere. I've logged into the zookeeper CLI and ensured the port number is correct thusly:
snerd#powerglove:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31f1093495ba compose_zookeeper "/opt/zookeeper/bin/ 3 weeks ago Up About a minute 0.0.0.0:32770->2181/tcp,
0.0.0.0:32769->2888/tcp, 0.0.0.0:32768->3888/tcp zookeeper
here is the code I'm trying to use:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
client.create().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
As far as I can tell from the Curator getting started page, this should work. What am I missing?
edit1
just figured out that I'm able to pull data out of the zookeeper ensemble thusly:
System.out.println(new String(curatorFramework.getData().forPath("/larry-smells")));
but the create command is still blowing up.
edit2
stacktrace of the error:
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for /larry-smells/foop at
org.apache.zookeeper.KeeperException.create(KeeperException.java:103)
at
org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297) at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1040)
at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1023)
at
org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:99) at
org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1020)
at
org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:501)
at
org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:491)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:367)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:309)
at com.mycompany.app.App.main(App.java:35)
Edit: Apparently this error can occur if you're using the wrong combination of Curator in combination with Zookeeper. From curator.apache.org :
Curator 2.x.x - compatible with both ZooKeeper 3.4.x and ZooKeeper 3.5.x
Curator 3.x.x - compatible only with ZooKeeper 3.5.x and includes support for new features such as dynamic reconfiguration, etc.
It's hard to pinpoint your problem with only that error-code and not a stack trace, but some improvements I would suggest to make your application more stable is:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
//make sure you're connected to zookeeper.
client.blockUntilConnected();
//Make sure the parents are created.
client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
I also faced a similar exception, I used the below dependencies which are compatible and helps me to resolve the exception.
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>4.0.1</version>
</dependency>
I had the same problem.
I tried to use inTransaction () as explained here: http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.CuratorFramework on exercise 6
and seems to work.
client.inTransaction ().create().forPath("/larry-smells/foop", "tuna?".getBytes()).and ().commit ();
The issue is caused because of incompatibility.
To fix this, you need to change the version like it's explained here:
https://curator.apache.org/zk-compatibility.html
If this doesn't work, just look for the newest curator version which depends on a 3.4.x zookeeper version (currently '2.12.0').
#Massimo Da Ros solution works, but in new version Curator 4.0.0 inTransaction is deprecated, it's recommented use transaction method like below:
CuratorOp op = client.transactionOp().create()
.withMode(CreateMode.PERSISTENT)
.withACL(Ids.OPEN_ACL_UNSAFE)
.forPath("/test", "Data".getBytes());
result = client.transaction().forOperations(op).get(0).toString();
I faced similiar problem. I was using spring-cloud-starter-zookeeper-discovery which by itself of course has compatible zookeeper and curator versions.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
I checked the dependency tree and spring-cloud-starter-zookeeper-discovery Version 3.1.1. was using zookeeper Version 3.6.0
The problem was, in my docker-compose.yml I was using zookeeper Version 3.4!
So make sure your docker-compose.yml zookeeper version fits your maven zookeeper version.
version: "3.8"
services:
zookeeper:
container_name: zookeeper
image: zookeeper:3.6 <----------------- zookeeper version
ports:
- "2181:2181"

java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory

I want to create a web application running on Tomcat 7.0 with JRE JavaSE-1.6 on osx 10.8.
I am using a tutorial from the developers site and the error occurs when I try to call
clientSecrets = GoogleClientSecrets.load(new JacksonFactory(), reader);
I added the Jar google-http-client-jackson-1.16.0-rc.jar to my build path and still get following error:
java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
My classpath specifically points to this Jar too.
I just fixed this by changing the following lines:
Original: import com.google.api.client.json.jackson.JacksonFactory;
Modified: import com.google.api.client.json.jackson2.JacksonFactory;
I had a similar problem and solved it by manually adding the required JAR's to my WEB-INF\lib folder outside Eclipse.
From this page here, it says you need 3 libraries:
1) The Generated Java client library for BigQuery
2) The Google HTTP Client Library for Java
3) The Google OAuth Client Library for Java
Do you have them all? It sounds like you have #2, but it sounds like you're missing the google HTTP client.
In POM add below dependency-
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-gson</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.34.1</version>
</dependency>
Note: In above dependency version can be changed
2.Import statement
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
Usage
private static final JsonFactory JSON_FACTORY =
GsonFactory.getDefaultInstance();
GoogleClientSecrets clientSecrets =GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(in));

Plugin works on Jira 5.2.10, but does not on 6.0

Made plugin for Jira with data exchange via servlet (using FileUploadServlet).
Testing on Jira 5.2.10 was OK, but on 6.0 there is a trouble:
2013-06-27 21:46:26,575 http-bio-8080-exec-24 ERROR anri 1306x1054x1 4bhuqg 169.254.57.250 /plugins/servlet/smartActDataServlet [atlassian.plugin.module.PrefixDelegatingModuleFactory] Detected an error (NoClassDefFoundError) instantiating the module for plugin 'com.polontech.jira.plugin.activity.smartact.SmartAct' for module 'dataServlet': org/apache/commons/fileupload/FileUploadException. This error is usually caused by your plugin using a imported component class that itself relies on other packages in the product. You can probably fix this by adding the missing class's package to your instructions; for more details on how to fix this, see https://developer.atlassian.com/display/DOCS/NoClassDefFoundError .
2013-06-27 21:46:26,577 http-bio-8080-exec-24 ERROR anri 1306x1054x1 4bhuqg 169.254.57.250 /plugins/servlet/smartActDataServlet [atlassian.plugin.servlet.DefaultServletModuleManager] Unable to create servlet
com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
Why? What's the difference between 5.2.10 and 6.0? How to solve the problem?
As I get, problem is with FileUpload. Maybe, there is a way to add this to my project?
dependencies are on their place:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
Error seems very vague. We cannot know what the difference is but as with every software product things change between versions and stuff works, breaks or is deprecated.
Go to the Atlassian Support and Answers sites and get the answer you're looking for from the guys that develop JIRA.They'll know how to help.
Also review all the information on https://developer.atlassian.com/display/JIRADEV/Preparing+for+JIRA+6.0
since 6.0 is a major release
Problem solved. Just check the version of all dependencies: I had to use common-fileupload-1.2.2:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>