C# Rabbitmq RPC模式服务器超时解决方案

利用2个task实现,看红字,直接看代码
public string Call(string rpc_queue, byte[] obj)
{
string rstr = “no”;
var channel = this.GetModel(RpcChannel); channel.ContinuationTimeout = TimeSpan.FromSeconds(10);
channel.BasicPublish(exchange: “”, routingKey: rpc_queue, basicProperties: props, body: obj);
channel.BasicConsume(consumer: consumer, queue: replyQueueName, autoAck: true);
Task[] tasks = new Task[2];
tasks[0] = Task.Run(async () =>
{
await Task.Delay(6000);//超时
respQueue.Add(rstr);
//respQueue.CompleteAdding();
});
tasks[1] = Task.Run(() =>
{
rstr = respQueue.Take();
});
try
{
Task.WaitAll(tasks);
}
catch (AggregateException ae)
{
foreach (var ex in ae.InnerExceptions)
Console.WriteLine(” {0}: {1}”, ex.GetType().Name, ex.Message);
}
return rstr;
}

C#动态编译表达式

下面是原始方案
public object ComplierCode(string expression, ILogService logService, out string errorString)
{
string code = WrapExpression(expression);
object retvalue = null;
errorString = “”;
CSharpCodeProvider csharpCodeProvider = new CSharpCodeProvider();
try
{
//编译的参数
CompilerParameters compilerParameters = new CompilerParameters
{
CompilerOptions = “/t:library”,
GenerateInMemory = true
};
//开始编译
CompilerResults compilerResults = csharpCodeProvider.CompileAssemblyFromSource(compilerParameters, code);
if (compilerResults.Errors.Count > 0)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < compilerResults.Errors.Count; i++) { sb.Append(sb.Length > 0 ? “;” : “”);
sb.Append(compilerResults.Errors[i].ErrorText);
}
errorString = sb.ToString();
throw new Exception(“编译出错!” + sb.ToString());
}

Assembly assembly = compilerResults.CompiledAssembly;
Type type = assembly.GetType(“ExpressionCalculate”);
MethodInfo method = type.GetMethod(“Calculate”);
retvalue = method.Invoke(null, null);
}
catch (Exception ex)
{
logService.WriteLog(“编译出错,code=” + code, ex);
}
finally
{
csharpCodeProvider.Dispose();
}
return retvalue;
}

private string WrapExpression(string expression)
{
string code = @”
using System;

class ExpressionCalculate
{
public static object Calculate()
{
return {0};
}
}
“;
return code.Replace(“{0}”, expression);
}
其他方案:https://github.com/davideicardi/DynamicExpresso

Linux CentOS7安装NET Core

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.2-2.2.108-1

安装守护进程
yum install supervisor
systemctl enable supervisord.service
systemctl start supervisord.service
systemctl status supervisord.service
vi /etc/supervisord.conf(修改9001端口注释,打开防火墙,重启)
systemctl restart supervisord.service
参考:https://my.oschina.net/weidedong/blog/747428

C#动态执行javascript

Create a file in Notepad with only these contents:

class EvalClass { function Evaluate(expression: String) { return eval(expression); } }
Save the file as C:\MyEval.js

Open a VS2005 Command Prompt (Start, Programs, VS2005, VS2005 Tools)

Type Cd\ to get to C:\

Type

jsc /t:library C:\MyEval.js
A new file is created named MyEval.dll.

Copy MyEval.dll to the project and reference it (also reference Microsoft.Jscript.dll).

Then you should be able to call it like this:

Dim jScriptEvaluator As New EvalClass
Dim objResult As Object
objResult = jScriptEvaluator.Evaluate(“1==1 && 2==2”)
其他方式:https://github.com/davideicardi/DynamicExpresso(支持netcore)

debian9安装mariadb导致密码无效问题

debian9默认就是mariadb这个数据库,mysql一样
sudo apt install mariadb-server
sudo -i
mysql -u root -p
1 use mysql; 然后敲回车
2 update user set authentication_string=password(“你的密码”) where user=”root” 然后敲回车
3 flush privileges 然后敲回车上面操作都没有用的
#select user,plugin from user后看看,错误原因是因为plugin root的字段是auth_socket,那我们改掉它为下面的mysql_native_password
update user set authentication_string=password(“123456”),plugin=’mysql_native_password’ where user=’root’;
flush privileges;
到处都是坑
参考:http://blog.sina.com.cn/s/blog_7c987bee0102yz76.html

NET之NLOG使用

安装
Install-Package NLog.Config
配置文件

  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Trace" internalLogToConsole="false" internalLogFile="nlog-internal.log">
  <targets  async="true">
    <target name="logfile" xsi:type="File" fileName="file.txt" />
    <target name="logconsole" xsi:type="Console" />
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="logconsole,logfile" />
    <logger name="*" minlevel="Debug" writeTo="logconsole" />
    <logger name="*" minlevel="Error" writeTo="logconsole,logfile" />
  </rules>
</nlog>  

使用
public static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
Logger.Error("Error" + (e.Source as AccordionStyleControl).Tag.ToString());

时序数据库InfluxDB在centos7安装使用

安装过程:
curl -O https://dl.influxdata.com/influxdb/releases/influxdb-1.7.7.x86_64.rpm
yum install influxdb-1.7.7.x86_64.rpm
systemctl start influxdb
systemctl status influxdb
配置安全选项
vim /etc/influxdb/influxdb.conf
[http]
enabled = true
bind-address = “:8086”
auth-enabled = true
log-enabled = true
https暂不开启
登录
influx -precision rfc3339
有密码登录
influx -precision rfc3339 -username ‘admin’ -password ‘admin’
设置密码(必须登录,先停止安全配置,重启influxdb)
CREATE USER admin WITH PASSWORD ‘‘ WITH ALL PRIVILEGES
数据库连接使用
NET:https://github.com/influxdata/influxdb-java
java:https://github.com/AdysTech/InfluxDB.Client.Net

Centos7安装mysql5.6

wget http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64//mysql-community-release-el7-5.noarch.rpm
rpm -Uvh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
systemctl start mysql
systemctl status mysql
mysql -u root
use mysql;
update user set password=PASSWORD("root") where User='root';
update user set host='%' where Host='localhost' and User='root';
flush privileges;