项目初始化
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="RabbitMQ" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
10
.idea/runConfigurations.xml
generated
Normal file
10
.idea/runConfigurations.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
15
pom.xml
15
pom.xml
@@ -4,7 +4,7 @@
|
||||
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>org.example</groupId>
|
||||
<groupId>io.jiulinxiri</groupId>
|
||||
<artifactId>RabbitMQ</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
@@ -13,4 +13,17 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rabbitmq</groupId>
|
||||
<artifactId>amqp-client</artifactId>
|
||||
<version>5.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
42
src/main/java/io/jiulinxiri/rabbitmq/one/Consumer.java
Normal file
42
src/main/java/io/jiulinxiri/rabbitmq/one/Consumer.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package io.jiulinxiri.rabbitmq.one;
|
||||
|
||||
import com.rabbitmq.client.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* 消费者
|
||||
*/
|
||||
public class Consumer {
|
||||
public static final String QUEUE_NAME = "hello";
|
||||
|
||||
public static void main(String[] args) throws IOException, TimeoutException {
|
||||
// 创建连接工程
|
||||
ConnectionFactory factory = new ConnectionFactory();
|
||||
// 设置连接地址
|
||||
factory.setHost("shop.jiulinxiri.io");
|
||||
// 设置端口
|
||||
// factory.setPort(15672);
|
||||
// 设置用户名
|
||||
factory.setUsername("jiulinxiri");
|
||||
// 设置密码
|
||||
factory.setPassword("123Abc@@");
|
||||
// 建立连接
|
||||
Connection connection = factory.newConnection();
|
||||
// 获取信道
|
||||
Channel channel = connection.createChannel();
|
||||
|
||||
DeliverCallback deliverCallback = (coustomerTag, message) -> {
|
||||
System.out.println(new String(message.getBody())q);
|
||||
};
|
||||
|
||||
CancelCallback cancelCallback = (coustomerTag) -> {
|
||||
System.out.println("消费中断");
|
||||
};
|
||||
/**
|
||||
*
|
||||
*/
|
||||
channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
|
||||
}
|
||||
}
|
48
src/main/java/io/jiulinxiri/rabbitmq/one/Producer.java
Normal file
48
src/main/java/io/jiulinxiri/rabbitmq/one/Producer.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package io.jiulinxiri.rabbitmq.one;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class Producer {
|
||||
public static final String QUEUE_NAME = "hello";
|
||||
|
||||
public static void main(String[] args) throws IOException, TimeoutException {
|
||||
// 创建连接工程
|
||||
ConnectionFactory factory = new ConnectionFactory();
|
||||
// 设置连接地址
|
||||
factory.setHost("shop.jiulinxiri.io");
|
||||
// 设置端口
|
||||
// factory.setPort(15672);
|
||||
// 设置用户名
|
||||
factory.setUsername("jiulinxiri");
|
||||
// 设置密码
|
||||
factory.setPassword("123Abc@@");
|
||||
// 建立连接
|
||||
Connection connection = factory.newConnection();
|
||||
// 获取信道
|
||||
Channel channel = connection.createChannel();
|
||||
/**
|
||||
* 生成队列
|
||||
* 1.队列名称
|
||||
* 2.从列里面的消息是否持久化(磁盘)默认情说消息存储在内存中
|
||||
* 3.该以列是否只供一个消费者进行消费 是否进行消息共享,true可以多个消费者消券 false:只能一个消费者消费
|
||||
* 4.是否自动册除 最后一个消费者端开连接以后 该队一句是否自动州除 true自动删除 false不自动删除
|
||||
* 5. 其它参数
|
||||
*/
|
||||
channel.queueDeclare(QUEUE_NAME,false, false,false,null);
|
||||
String message = "Hello World!";
|
||||
/**
|
||||
* 1. 发送到哪个交换机
|
||||
* 2.路由的key值是哪个 本次是从列的名称
|
||||
* 3. 其它参数信息
|
||||
* 4 发送消总
|
||||
*/
|
||||
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
|
||||
System.out.println("消息发送完毕");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user