erlang

C#调用RabbitMQ实现消息队列

好久不见. 提交于 2020-07-27 13:08:08
前言 我在刚接触使用中间件的时候,发现,中间件的使用并不是最难的,反而是中间件的下载,安装,配置才是最难的。 所以,这篇文章我们从头开始学习RabbitMq,真正的从头开始。 关于消息队列 其实消息队列没有那么神秘,我们这样想一下,用户访问网站,最终是要将数据以HTTP的协议的方式,通过网络传输到主机的某个端口上的。 那么,接收数据的方式是什么呢?自然是端口监听啦。 那消息队列是什么就很好解释了? 它就是端口监听,接到数据后,将数据排列起来。 那这件事,我们不用中间件能做吗? 当然能做啦,写个TCP/UDP/Socket的软件就可以做啦。 举个简单的例子,如下图: 既然自己可以做消息队列,那为什么要用RabbitMQ? 因为,RabbitMQ成熟的开源中间件,可靠性有保证,bug少,性能也非常好。 而C#代码默认是使用托管内存的,所以,想写出媲美RabbitMQ性能的消息队列,就必须离开我们常用的托管内存,使用非托管内存,但这个代价就太大了;而且最终能否达到RabbitMQ的性能水平还是个未知数。 还有就是RabbitMQ除了基础的消息队列管理,还有很多很强大的额外功能,而自己开发消息队列,很难如此尽善尽美。 ---------------------------------------------------------------------------------------

高性能队列RabbitMQ在windows下的安装

↘锁芯ラ 提交于 2020-07-26 19:31:37
RabbitMQ在windows下的安装 RabbitMQ 它依赖于Erlang,在window上安装时,需要 先安装Erlang 。 首先确定你的window电脑是32位还是64位,然后下载对应版本的Erlang软件。以下的安装以window 64位电脑举例。 Erlang/OTP包 的下载地址: http://www.erlang.org/download.html Erlang/OTP(otp_win64_17.5.exe)的安装步骤: 运行 otp_win64_17.5.exe 点击“Next”,选择安装的目录,这里为D:\java\erl6.4 点击“Next”,点击“Install”开始安装,安装完成。(可以留意一下里面的选项) RabbitMQ Server的下载与安装 RabbitMQ的下载地址: http://www.rabbitmq.com/download.html RabbitMQ的安装步骤: 直接运行rabbitmq-server-3.5.2.exe 点击"Next",选择安装的目录,这里为D:\java\RabbitMQ_Server 点击"Install",点击"Finish",安装成功。(可以留意一下里面的选项) ps:安装完Rabbit MQ以后,服务会自动运行,这时环境变量里的ERLANG_HOME会自动生成,在”环境变量”中检查是否存在

String regex matching in Erlang

别说谁变了你拦得住时间么 提交于 2020-07-05 07:48:07
问题 How would I do regex matching in Erlang? All I know is this: f("AAPL" ++ Inputstring) -> true. The lines that I need to match "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n" In Perl regex: ^AAPL,* (or something similar) In Erlang? 回答1: Use the re module, e.g.: ... String = "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n", RegExp = "^AAPL,*", case re:run(String, RegExp) of {match, Captured} -> ... ; nomatch -> ... end, ... 来源: https://stackoverflow.com/questions/2828160

Knowing the number of parameters of a passed function (erlang)

时光怂恿深爱的人放手 提交于 2020-06-25 10:13:50
问题 In ERLANG: Assume we have a function f() that takes F1 as inputs where F1 is a function. Is there a way to know the number of input parameters of F1. I feel somehow there IS a solution, but I am not sure. for instance: -module(high). -compile(export_all). f1() -> 1. f2(X) -> X. f3(X, Y) -> {X,Y}. run(F) -> io:format("F ~p ~n", [F]). So, is there any way for function run/1 to know information about the passed function [mainly the number of input parameters of the passed function]. Note: Please

ERLANG - binary string to integer or float

◇◆丶佛笑我妖孽 提交于 2020-06-24 12:01:27
问题 I have binary strings in the form of either: <<"5.7778345">> or <<"444555">> I do not know before hand whether it will be a float or integer. I tried doing a check to see if it is an integer. Does not work since it is binary. And tried converting binary to list then check if int or float. Not much success with that. It needs to be a function such as binToNumber(Bin) -> %%Find if int or float Return. Anyone have a good idea of how to do this? All the Best 回答1: No quick way to do it. Use

Erlang simple_one_for_one supervisor does not restart child

有些话、适合烂在心里 提交于 2020-06-18 12:35:13
问题 I have a test module and a simple_one_for_one supervisor. test.erl -module(test). -export([ run/1, do_job/1 ]). run(Fun) -> test_sup:start_child([Fun]). do_job(Fun) -> Pid = spawn(Fun), io:format("started ~p~n", [Pid]), {ok, Pid}. test_sup.erl -module(test_sup). -behaviour(supervisor). -export([start_link/0]). -export([init/1]). -export([start_child/1]). start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). init(_Args) -> SupFlags = #{strategy => simple_one_for_one, intensity

a bug in erlang node after an error at another node

雨燕双飞 提交于 2020-06-17 09:56:06
问题 i created 2 erlang nodes in the same Windows machine with two cmd windows:'unclient@MYPC' and 'unserveur@MYPC' , the server code is very simple : -module(serveur). -export([start/0,recever/0,inverse/1]). %%%% start() -> process_flag(trap_exit,true), Pid=spawn_link(serveur,recever,[]), register(ownServer, Pid). %%%% recever() -> receive {From, X} ->From ! {ownServer,1/X} end. %%%% inverse(X) -> ownServer!{self(), X}, receive {'EXIT',_, _} ->start(), sorry; {ownServer, Reply} ->Reply end. so at

How to concat a list of integers to a string in Erlang?

亡梦爱人 提交于 2020-06-16 05:49:18
问题 I have this tuple that looks like this: {127,0,0,1} Now I want to pass that tuple as the string "127.0.0.1" to an external lib (a geo IP lib). What's the best way to convert this tuple to the string? 回答1: You can use this: ip_to_string({I1, I2, I3, I4}) -> lists:concat([I1,".",I2,".",I3,".",I4]); ip_to_string({v6, Addr}) -> inet_parse:ntoa(Addr). 回答2: You can always use inet_parse:ntoa/1 : 1> inet_parse:ntoa({127,0,0,1}). "127.0.0.1" 2> inet_parse:ntoa({0,0,0,0,0,0,0,1}). "::1" 来源: https:/

How to concat a list of integers to a string in Erlang?

让人想犯罪 __ 提交于 2020-06-16 05:49:10
问题 I have this tuple that looks like this: {127,0,0,1} Now I want to pass that tuple as the string "127.0.0.1" to an external lib (a geo IP lib). What's the best way to convert this tuple to the string? 回答1: You can use this: ip_to_string({I1, I2, I3, I4}) -> lists:concat([I1,".",I2,".",I3,".",I4]); ip_to_string({v6, Addr}) -> inet_parse:ntoa(Addr). 回答2: You can always use inet_parse:ntoa/1 : 1> inet_parse:ntoa({127,0,0,1}). "127.0.0.1" 2> inet_parse:ntoa({0,0,0,0,0,0,0,1}). "::1" 来源: https:/

GC performance in Erlang

拜拜、爱过 提交于 2020-05-26 07:33:10
问题 I've started programming erlang recently and there are a few things I want to understand regarding GC. As far as I understand there is a generational GC for the private heap of each process and a reference counting GC for the global shared heap. What I would like to know is if there is anyway to get: How many number of collection cycles? How many bytes are allocated and deallocated, on a global level or process level? What are the private heaps, and shared heap sizes? And can we define this