C语言系统化精讲 重塑你的编程思想 打造坚实的开发基础
**下载地址:百度云盘
**
修炼内功最强语言,训练编程思想最有效语言,圣经般存在的语言,2020 TIOBE排行冠军语言——这些说的,都是C语言。每个优秀开发者都应该精通C语言,这门课程就是为所有没学过、没学好C语言的你专属打造,多种编程语言技术专家bennyhuo独家分享,带你系统、高效、轻松啃透C语言这个硬骨头!
适合人群
希望获得更深层次进阶语言的开发者
希望夯实语言基础的开发者
希望精雕细琢掌握多门语言的开发者
有面试/跳槽/晋升需求的开发者和在校生
技术储备要求
零门槛,有计算机基础、操作系统、编程基础和经验更佳
1.基本行列音讯发送和接纳
简单模型,使用默许exchange,发送到指定queue,1对1发送接纳。
发送方-->(默许Exchange)-->Queue-->接纳方
(1)发送指定行列音讯
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class SendDemo {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = null;
try {
connection = factory.newConnection();
Channel channel = connection.createChannel();
// 界说非耐久queue
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
// 发送音讯到默许exchange,指定queue
channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}
(2)经过拉形式消费音讯(不引荐)
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.GetResponse;
/**
* 经过拉形式消费音讯(不引荐)
*
* @date 2019年3月8日 下午3:31:14
*/
public class RecvPull {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = null;
try {
connection = factory.newConnection();
Channel channel = connection.createChannel();
// 界说非耐久queue
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
// 开端消费指定queue的音讯
while (true) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
GetResponse response = channel.basicGet(QUEUE_NAME, true);
if (response == null) {
continue;
}
String responseStr = new String(response.getBody());
System.out.println("responseStr: " + responseStr);
}
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}
(3)经过推形式消费音讯(引荐)
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
/**
* 经过推形式消费音讯(引荐)
*
* @date 2019年3月8日 下午3:31:56
*/
public class RecvPush {
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = null;
try {
connection = factory.newConnection();
Channel channel = connection.createChannel();
// 界说非耐久queue
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
// 界说监听消费者
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
// 开端消费指定queue的音讯
channel.basicConsume(QUEUE_NAME, true, consumer);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}