This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly ConnectionFactory _connFactory = new ConnectionFactory(); | |
private IConnection _conn; | |
private IModel _chan; | |
private const string Host = "192.168.1.200"; | |
private const string UserName = "guest"; | |
private const string Password = "guest"; | |
private void InitRabbit() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 生成匿名Queue | |
var resultQ = _chan.QueueDeclare( | |
queue: "", | |
durable: false, | |
exclusive: true, | |
autoDelete: true, | |
arguments: null | |
); | |
string qName = resultQ.QueueName; // 得到Queue名称 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IBasicProperties msgProps = new BasicProperties(); | |
msgProps.DeliveryMode = 2; // 1=临时,2=永久 | |
msgProps.ContentType = "application/json"; // mime type | |
msgProps.ReplyTo = qName; // 设置ReplyTo为匿名Queue,用于返回结果 | |
// 发送消息 | |
_chan.BasicPublish( | |
exchange:ExchangeName, | |
routingKey: RoutingKeyName, | |
basicProperties: msgProps, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public delegate void UpdateMsgBodyDelegate(string aString); | |
// 使用Consumer监控匿名Queue | |
var evtConsumer = new EventingBasicConsumer(){ Model = _chan}; | |
evtConsumer.Received += Notify; | |
_chan.BasicConsume( | |
queue: qName, | |
noAck: true, // 不要返回ACK | |
consumer: evtConsumer | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 声明Exchange | |
_chan.ExchangeDeclare( | |
exchange: ExchangeName, | |
type: ExchangeType.Direct, | |
durable: true, | |
autoDelete: false, | |
arguments: null | |
); | |
// 声明Queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Notify(IBasicConsumer sender, BasicDeliverEventArgs args) | |
{ | |
IBasicProperties msgProps = args.BasicProperties; | |
sender.Model.BasicAck(args.DeliveryTag, false); // 返回ACK应答信息 | |
// 得到公式,并进入计算 | |
string msgBody = Encoding.ASCII.GetString(args.Body); | |
var calcMessage = JsonConvert.DeserializeObject<CalcMessage>(msgBody); | |
// 显示公式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string result = ""; | |
try | |
{ | |
// 按输入公式文本计算结果 | |
ExpressionContext context = new ExpressionContext(); | |
context.Imports.AddType(typeof (Math)); | |
// context.Variables["a"] = 100; 可以在表达式内使用变量,再使用Variables传递变量值进行计算 | |
IDynamicExpression eDynamic = context.CompileDynamic(calcMessage.Formula); // "sqrt(a) + pi" | |
result = eDynamic.Evaluate().ToString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 使用QueueingBasicConsumer循环方式,取得队列 | |
*/ | |
var consumer = new QueueingBasicConsumer(_chan); | |
string consumerTag = _chan.BasicConsume("hello-queue", | |
false, consumer); | |
while (true) | |
{ | |
BasicDeliverEventArgs evtArgs = (BasicDeliverEventArgs) consumer.Queue.Dequeue(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.animated { | |
-webkit-animation: 1s ease; | |
-moz-animation: 1s ease; | |
-ms-animation: 1s ease; | |
-o-animation: 1s ease; | |
animation: 1s ease; | |
-webkit-animation-fill-mode: both; | |
-moz-animation-fill-mode: both; | |
-ms-animation-fill-mode: both; | |
-o-animation-fill-mode: both; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import collections | |
# 敏感关键字匹配在线产品查找 | |
title_width = 60 | |
FIELD_ITEMID = 0 | |
FIELD_SKU = 1 | |
FIELD_TITLE = 2 |
OlderNewer