erlang

RabbitMQ 集群&使用说明

半城伤御伤魂 提交于 2019-12-29 12:27:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 集群 集群所有机器都安装好erlang和RabbitMQ(安装方式见上一篇) Rabbitmq的集群是依附于erlang的集群来工作的,必须保证各节点erlang的cookie是一样的(最好从主节点copy到各个节点上):/var/lib/rabbitmq/.erlang.cookie 启动各个节点的RabbitMQ # 启动服务 service rabbitmq-server start rabbitmqctl start_app # 把节点添加到集群中(默认磁盘持久化,--ram表示内存) rabbitmqctl join_cluster --ram rabbit@[hostname] # 如果要更改节点持久化类型,需要先停再改 rabbitmqctl stop_app rabbitmqctl change_cluster_node_type disc(ram) 这时候在web页面的overview就能看到你集群中所有的节点情况了。 镜像配置 集群并不能保证高可用,假设节点2宕机了,那么节点2上面的queue,exchange和message都会丢失,即使是用磁盘持久化,在宕机这段时间内,该queue,exchange都无法提供服务。 于是,诞生了镜像:把A节点的内容镜像到B节点(相当于备份)

Explanation of lists:fold function

筅森魡賤 提交于 2019-12-29 09:05:28
问题 I learning more and more about Erlang language and have recently faced some problem. I read about foldl(Fun, Acc0, List) -> Acc1 function. I used learnyousomeerlang.com tutorial and there was an example (example is about Reverse Polish Notation Calculator in Erlang): %function that deletes all whitspaces and also execute rpn(L) when is_list(L) -> [Res] = lists:foldl(fun rpn/2, [], string:tokens(L," ")), Res. %function that converts string to integer or floating poitn value read(N) -> case

Explanation of lists:fold function

放肆的年华 提交于 2019-12-29 09:05:13
问题 I learning more and more about Erlang language and have recently faced some problem. I read about foldl(Fun, Acc0, List) -> Acc1 function. I used learnyousomeerlang.com tutorial and there was an example (example is about Reverse Polish Notation Calculator in Erlang): %function that deletes all whitspaces and also execute rpn(L) when is_list(L) -> [Res] = lists:foldl(fun rpn/2, [], string:tokens(L," ")), Res. %function that converts string to integer or floating poitn value read(N) -> case

Including the Erlang client library from Riak in Nitrogen

心已入冬 提交于 2019-12-29 08:04:11
问题 i'm just starting up with a web app using nitrogen and everything is going well. But i also want my app to interface with a riak db that i set up and i'm having some trouble. I'm confused as to how I "include" the erlang client interface so that my code in nitrogen can access it. (https://wiki.basho.com/display/RIAK/Erlang+Client+PBC) I'm new to erlang and nitrogen, but i mean in general, for erlang, how do i include other libraries as reference? Do i just take the compiled beam files and

Parameterised Modules in Erlang

南笙酒味 提交于 2019-12-29 05:30:31
问题 I was going through mochiweb source code and got to see something i never used before. The module declaration especially in mochiweb_request and mochiweb_response modules found in the mochiweb http library. Here is how the module begins: -module(mochiweb_request,[Socket, Method, RawPath, Version, Headers]). -author(...). Then in the module you see get(socket) -> Socket;get(method)-> Method; .... This has confused me. When i tried getting the module info of one of these such module, the

How do you URL encode parameters in Erlang?

旧街凉风 提交于 2019-12-29 05:03:08
问题 I'm using httpc:request to post some data to a remote service. I have the post working but the data in the body() of the post comes through as is, without any URL-encoding which causes the post to fail when parsed by the remote service. Is there a function in Erlang that is similar to CGI.escape in Ruby for this purpose? 回答1: You can find here the YAWS url_encode and url_decode routines They are fairly straightforward, although comments indicate the encode is not 100% complete for all

centos7.x 安装 RabbitMQ

余生颓废 提交于 2019-12-29 00:27:01
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 官网说明: https://www.rabbitmq.com/install-rpm.html#downloads CentOS 8.x,7.x和6.x(有三个独立的RPM软件包:一个用于8.x系列,一个用于7.x,一个用于6.x) 需要root用户或者sudo权限 1. 下载&安装rpm仓库,安装erlang # 不推荐离线安装(需要装一堆环境才能编译) wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm rpm -Uvh erlang-solutions-1.0-1.noarch.rpm yum install erlang # 查看版本,以便后面找对应的rabbitmq包 erl -version 2. 安装RabbitMQ 从官网下载对应的rpm包,版本一定要是兼容列表内的: https://www.rabbitmq.com/which-erlang.html # 我从github下(版本随便选),也可以从官网下 wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.18/rabbitmq-server-3.7.18

is erlangs recursive functions not just a goto?

醉酒当歌 提交于 2019-12-28 15:26:10
问题 Just to get it straight in my head. Consider this example bit of Erlang code: test() -> receive {From, whatever} -> %% do something test(); {From, somethingelse} -> %% do something else test(); end. Isn't the test() call, just a goto? I ask this because in C we learned, if you do a function call, the return location is always put on the stack. I can't imagine this must be the case in Erlang here since this would result in a stackoverflow. In basic. We had 2 different ways of calling functions

Convert erlang terms to string, or decode erlang binary

南笙酒味 提交于 2019-12-28 14:08:08
问题 I have an erlang program which generates data. This data needs to be transferred via udp to a non-erlang program for further processing. I already have this part working - sending the data via udp and receiving it on the other non-erlang side. Here's the problem. The data (erlang terms like tuples containing lists) doesn't seem to be able to go over "as is" (i.e. I can't just send arbitrary erlang terms). It apparently needs to be converted to either text or binary first. Converting to binary

Can someone explain the structure of a Pid in Erlang?

孤者浪人 提交于 2019-12-27 16:42:49
问题 Can someone explain the structure of a Pid in Erlang? Pids looks like this : <A.B.C> , e.g. <0.30.0> , but i would like to know what is the meaning of these three "bits" : A, B and C. 'A' seems to be always 0 on a local node, but this value changes when the Pid's owner is located on another node. Is it possible to directly send a message on a remote node using only the Pid ? Something like that : <4568.30.0> ! Message , without having to explicitely specify the name of the registered process