简体   繁体   English

RabbitMQ Java客户端-Java依赖关系(标准库?)

[英]RabbitMQ Java Client - Java Dependencies (standard libraries?)

I need to integrate RabbitMQ with another system that runs on Java. 我需要将RabbitMQ与另一个在Java上运行的系统集成。 So I went to the official website , downloaded the package and copied it to my classpath. 因此,我去了官方网站 ,下载了软件包并将其复制到我的类路径中。 Then I followed the basic tutorial , and I verified that importing external libraries work. 然后,我遵循了基础教程 ,并验证了导入外部库的工作。

The problem I face now is probably very easy to solve for a Java developer: which standard Java libraries do I have to import to make the following code work? 对于Java开发人员来说,我现在面临的问题可能很容易解决:为了使以下代码正常工作,我必须导入哪些标准Java库?

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
...
ConnectionFactory factory = new ConnectionFactory();

without running into import errors like this: 不会遇到这样的导入错误:

Line 51, Column 18: No applicable constructor/method found for actual parameters "java.lang.String"; 
candidates are: "void com.rabbitmq.client.ConnectionFactory.setPort(int)"

I tried things like these, but I have no idea how that works in Java, so I would like to have some clarification. 我尝试了类似的方法,但是我不知道它在Java中是如何工作的,所以我想澄清一下。 For example, when should I use an asterisk? 例如,何时应使用星号?

import java.lang.String;
import java.lang.String.*;

By the way, the system I am trying to integrate RabbitMQ with is Pentaho Data Integration (aka Kettle). 顺便说一句,我要与RabbitMQ集成的系统是Pentaho Data Integration(又名Kettle)。

First, get rid of your java.lang imports. 首先,摆脱您的java.lang导入。

Second, call setPort with an int and not a String as described in the API . 其次,使用int而不是API中描述的String调用setPort

Just including the amqp-client-${version} jar in classpath should be sufficient. 仅在类路径中包含amqp-client-$ {version} jar就足够了。 Astreix is used to import all classes from a package. Astreix用于从包中导入所有类。 Class names in java begins with a caps while package names are in small case. Java中的类名以大写字母开头,而程序包名称为小写字母。 So, java.lang is a package and String is a class. 因此,java.lang是一个包,而String是一个类。 By default all classes of java.lang package are imported in a Java program and you do not need to write import java.lang.String; or import java.lang.*; 默认情况下,所有java.lang包类都导入Java程序中,而无需编写import java.lang.String; or import java.lang.*; import java.lang.String; or import java.lang.*;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM