erlang

Erlang gen_server with long-running tasks

筅森魡賤 提交于 2020-01-12 05:21:19
问题 Good day, I have a gen_server process which does some long-running state-updating tasks periodically in handle_info : handle_info(trigger, State) -> NewState = some_long_running_task(), erlang:send_after(?LOOP_TIME, self(), trigger), {noreply, NewState}. But when such task runs, then whole server gets unresponsive and any call to it leads to whole server crash: my_gen_server:status(). ** exception exit: {timeout,{gen_server,call,[my_gen_server,status]}} in function gen_server:call/2 How it is

EMQ X Broker 连接kafka插件(一)

女生的网名这么多〃 提交于 2020-01-12 04:00:23
距离上一次发博客已经很久。这次重新做EMQ的时候发现,EMQ X Broker 的架构设计改变了,使得在做插件的路上诸多坎坷。话不多说赶紧开始。 首先,源码编译安装EMQ X Broker: 只有源码编译了,我们才可以做里面的插件。 源码编译: 1.安装Erlang 1.下载erlang 在下载前,先安装环境 yum -y install perl-devel.x86_64 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel Erlang网站:http://erlang.org/download/ 进入Erlang网站,下载erlang版本otp_src_22.X.tar.gz() ——————————————————————————————————— ——————————————————————————————————— 下载完,上传后解压 tar -zxvf otp_src_22.1.tar.gz 创建erlang目录( 这里注意了 ,/home/erlang是自定义目录,看自己来定) mkdir /home/erlang 进入到刚刚解压出来的otp_src_22.1文件夹设置编译安装路径,再编译安装 cd otp_src_22.1 ./configure --prefix=

Erlang shell pretty print depth

白昼怎懂夜的黑 提交于 2020-01-12 03:20:28
问题 The erlang shell truncates long terms, for example: 6> lists:seq(1,1000). [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22, 23,24,25,26,27,28,29|...] How do I make it not do that? Or at least increase the depth before it truncates the term. I know I could do something like... io:format("~p~n",[lists:seq(1,1000)]). ... but I'd prefer to configure the shell to do what I want. 回答1: An alternative to io:format("~p", [Term]) is the shell built in function rp(Term) which does exactly that.

Erlang shell pretty print depth

非 Y 不嫁゛ 提交于 2020-01-12 03:19:33
问题 The erlang shell truncates long terms, for example: 6> lists:seq(1,1000). [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22, 23,24,25,26,27,28,29|...] How do I make it not do that? Or at least increase the depth before it truncates the term. I know I could do something like... io:format("~p~n",[lists:seq(1,1000)]). ... but I'd prefer to configure the shell to do what I want. 回答1: An alternative to io:format("~p", [Term]) is the shell built in function rp(Term) which does exactly that.

Setting up Emacs for programming Erlang

痴心易碎 提交于 2020-01-12 01:36:10
问题 Emacs is the IDE of choice for programming Erlang. There are plenty of good modes (distel, erlware-mode, the default erlang mode,...), but what are your recommendations for setting up Emacs for professional Erlang development? 回答1: Set up erlang-mode as described in the README, and then activate Flymake: (require 'erlang-flymake) That gives you highlighting of warnings and errors as you type. I'd recommend using erlang-mode from the latest Erlang/OTP release (R14A as I type this), regardless

erlang随笔3--OTP

安稳与你 提交于 2020-01-11 23:27:44
OTP最核心的概念就是行为。一个行为封装了某种常见的行为模式。可以把这些行为理解为某种应用程序框架。可以通过回调模块来 定制这些框架。OTP依靠行为引用了容错,扩容和动态代码升级等特性。所以在写回调模块的时候不需要再考虑容错之类的事务。 new() -> dictionary() 初始构造一个新的字典(其实是返回一个内部定义的dict记录record) store(Key, Value, Dict1) -> Dict2 以键值(Key - Value)对的形式存储在字典里。如果字典里已经存在 Key 的键,则把跟 Key 相关的值替换为 Value(覆盖) from_list(List) -> Dict 把一个 Key-Value 形式的列表转换为一个字典 size(Dict) -> int() 返回字典里键值对的个数 to_list(Dict) -> List 把字典转换成一个列表形式 append(Key, Value, Dict1) -> Dict2 给当前列表跟 Key 相关联的值附加上一个新值 Value(如果跟 Key 相关联的值不是一个列表值,将会抛出一个异常错误) EPL(erlang 公开协议) 1.原始的服务器程序【server1.erl + name_server.erl】 2.支持事务的服务器程序:在请求导致服务器程序出现异常时,会让给客户端代码异常退出

Iterate over a cartesian product in Erlang without generating a list first

不打扰是莪最后的温柔 提交于 2020-01-11 10:30:11
问题 What's the Erlang equivalent to the following Python code: for x in range(9): for y in range(9): for z in range(9): foo(x, y, z) I know I can generate the product first with C = [{X,Y,Z} || X<- lists:seq(1,9), Y<- lists:seq(1,9), Z<- lists:seq(1,9)] then foo([])->done; foo([H|T])->blah blah. How do I do it without an auxiliary list, using recursion only? 回答1: You could do it with three recursive functions. You might be able to do it with some complex pattern-matching in function head. But

Return value of a function in Erlang

自古美人都是妖i 提交于 2020-01-11 08:33:09
问题 What the following function will return? ok atom or Cmd? function_test() -> Cmd = os:cmd("ls"), io:format("The result of ls is:~p~n", [Cmd]). If it returns ok then how it should be rephrased to return Cmd while still using io:format? 回答1: In Erlang the last expression in your function is returned, in your case that would be the result of io:format which is ok . To return Cmd you can simply make it the last expression in your function: function_test() -> Cmd = os:cmd("ls"), io:format("The

RabbitMQ学习一环境搭建

别来无恙 提交于 2020-01-11 08:02:25
RabbitMq学习一环境搭建 一、下载及安装 (一)访问官网并进行下载https://www.rabbitmq.com RabbitMq基于Erlang开发因此还需下载和安装Mq的运行环境Erlang,注意Mq的版本要与Erlang相匹配,版本相兼容信息可在Mq官网查阅 (二)安装 先安装Erlang再安装Mq默认都是下一步直至结束。 再安装RabbitMq默认下一步直到结束。 下载地址:https://pan.baidu.com/s/1QWM8ZhuFE5hS1CMaWdAehw 经过测试新版本下安装可以直接访问RabbitMq的UI控制界面 http://localhost:15672 默认用户名和密码都是guest 二、在MQ中UI控制界面中进行用户管理 (一)创建用户 以超管身份登录http://localhost:15672选择Admin功能页进行用户的新增 (二)virtual hosts virtual hosts就相当于数据库(mySql的DB),只有给用户进行了授权那么用户才能进行访问和使用数据库 进行virtual hosts的创建,创建中一般以“/”进行开头 (三)对用户进行授权 (四)MQ中UI界面相关功能的介绍 实际开发中使用代码控制和操作mq,使用的就是amqp通信协议 来源: CSDN 作者: 平凡一哥 链接: https://blog.csdn

RabbiMQ重新安装会遇到的错误-SpiritMark

柔情痞子 提交于 2020-01-11 05:16:41
这里只做安装过程中遇到错误的介绍,不喜勿喷,如果对您有帮助右上角关注一下,是对我最大的肯定 重新安装的注意事项: 先卸载RabbitMQ,后卸载Erlang RabbitMQ卸载,选择uninstall.exe进行卸载 Erlang卸载,进入按照目录选择Uninstall.exe使用管理员权限运行进行卸载,卸载完成后将erl目录删除,如提示删除不了重启机器之后再进行删除。 先停止RabbitMQ服务 利用管理员权限进入dos命令窗口,执行 sc delete RabbitMQ,移除服务 找到任务管理器,查找epmd.exe进程,然后停止 利用regedit命令进入注册表编辑器。找到在此路径HKEY_LOCAL_MACHINE\SOFTWARE\Ericsson\下,将Erlang全部清除。 利用 everything And Listary 工具进行文件查找, 首先查询RabbitMQ,如下图所示,剩余文件可能会比这多,选择进行清理 转到用户文件夹:**C:\ Users \ [username]**,然后删除文件.erlang.cookie。删除 erlang的配置文件 Windows下安装RabbitMQ (1):下载 erlang ,原因在于RabbitMQ服务端代码是使用并发式语言erlang编写的,就像 开发Java需要安装JDK一样 下载地址: erlang ,双击