erlang

how to use multiple configuration files for RabbitMQ / Erlang

↘锁芯ラ 提交于 2020-01-01 06:24:51
问题 I am trying to setup a Spring based Java application which uses a locally installed RabbitMQ server for delivering messages between nodes. As some of you already know, the rabbitmq.config file can be used to configure various parameters and is loaded by the underlying Erlang node which the Rabbit server runs on. My problem is that I have a requirement that some of the configuration needs to be static and some needs to be dynamic , specifically, I need to be able to reconfigure the shovels

Erlang course concurrency exercise: Can my answer be improved?

旧街凉风 提交于 2020-01-01 05:31:06
问题 I am doing this exercise from the erlang.org course: 2) Write a function which starts N processes in a ring, and sends a message M times around all the processes in the ring. After the messages have been sent the processes should terminate gracefully. Here's what I've come up with: -module(ring). -export([start/2, node/2]). node(NodeNumber, NumberOfNodes) -> NextNodeNumber = (NodeNumber + 1) rem NumberOfNodes, NextNodeName = node_name(NextNodeNumber), receive CircuitNumber -> io:format("Node

Why is 'Infinity' not allowed in Erlang's floats?

前提是你 提交于 2020-01-01 04:59:07
问题 Erlang (and by extension Elixir) supports floating-point numbers. Some possible Floats: 1.2345 1.0e10 1.0e-42 Erlang supports NaN ( nan. in Erlang) (I am however yet to discover a method that outputs nan itself). However, Erlang does not have support for Infinity . While common standards like IEEE-754 state that one should return Infinity when doing things like 1.0/0.0 , instead, Erlang throws a bad arithmetic error . The same happens when attempting to make floats that are 'too large' like 1

erlang: uuid generator

只愿长相守 提交于 2020-01-01 04:47:07
问题 What module/library do you use to generate uuid? 回答1: For future googlers like myself, erlang-uuid from avtobiff works very simply. 回答2: from http://github.com/travis/erlang-uuid -module(uuid). -export([v4/0, to_string/1, get_parts/1]). -import(random). v4() -> v4(random:uniform(math:pow(2, 48)) - 1, random:uniform(math:pow(2, 12)) - 1, random:uniform(math:pow(2, 32)) - 1, random:uniform(math:pow(2, 30)) - 1). v4(R1, R2, R3, R4) -> <<R1:48, 4:4, R2:12, 2:2, R3:32, R4: 30>>. to_string(U) ->

Find all possible paths from one vertex in a directed cyclic graph in Erlang

匆匆过客 提交于 2020-01-01 03:21:05
问题 I would like to implement a function which finds all possible paths to all possible vertices from a source vertex V in a directed cyclic graph G. The performance doesn't matter now, I just would like to understand the algorithm. I have read the definition of the Depth-first search algorithm, but I don't have full comprehension of what to do. I don't have any completed piece of code to provide here, because I am not sure how to: store the results (along with A->B->C-> we should also store A->B

How do you install a module in erlang?

廉价感情. 提交于 2020-01-01 02:31:33
问题 I am new to Erlang and would like to to know how to install third party modules for use in my web application. Where do you place this files and what sort of commands do you execute? 回答1: If you wish to install 3rd party libs, like Mochiweb, system wide it's best to set it up under the $ERL_LIBS environment variable. I write a bit about it here and give examples of installing common tools here. It is probably best not to put anything inside Erlang's own code library(/usr/lib/erlang/lib) but

Getting gen_server/gen_fsm state for debugging

痞子三分冷 提交于 2020-01-01 02:16:07
问题 Is it possible to obtain the current state of a gen_server process (presumably by sending some system message)? It could be useful when debugging. Of course, I can add a message which returns the current state to handle_call : get_state(Server) -> gen_server:call(Server, '$get_state'). %% in every gen_server I want to debug ... handle_call('$get_state', _From, State) -> {reply, State, State}; ... but is there something built-in (even if it is a bit hacky)? 回答1: Use sys:get_status/1,2 function

rabbitmq安装记录

柔情痞子 提交于 2020-01-01 01:58:30
1 安装(注意erlang和rabbitmq版本问题) 环境: CentOS 6.5 其他环境安装方式略。 安装ErLang Erlang(['ə:læŋ])是一种通用的面向并发的编程语言,它由瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并发活动的编程语言和运行环境。 rpm --import https://packages.erlang-solutions.com/rpm/erlang_solutions.asc vi /etc/yum.repos.d/xxx (xxx是目录中的任意一个已有的yum列表文件) 在文件中增加下述内容: [erlang-solutions] name=Centos $releasever - $basearch - Erlang Solutions baseurl=https://packages.erlang-solutions.com/rpm/centos/$releasever/$basearch gpgcheck=1 gpgkey=https://packages.erlang-solutions.com/rpm/erlang_solutions.asc enabled=1 生成yum缓存信息 yum makecache 安装ErLang yum -y install erlang 检查安装结果

Erlang: Avoiding race condition with gen_tcp:controlling_process

前提是你 提交于 2019-12-31 22:25:17
问题 I am implementing simple tcp server with the following sequence: {ok, LS} = gen_tcp:listen(Port,[{active, true}, {reuseaddr, true}, {mode, list}]), {ok, Socket} = gen_tcp:accept(LS), Pid = spawn_link(M, F, [Socket]), gen_tcp:controlling_process(Socket, Pid) Using the option {active, true} might cause a race condition where a new packet arrives on the socket process before the "controlling_process" get called , which would result in {tcp,Socket,Data} message arriving to the father proccess

Authentication failed (rejected by the remote node), please check the Erlang cookie

余生颓废 提交于 2019-12-31 12:59:06
问题 I installed erlang and rabbitmq in the way mentioned in the official documentation. But then, when I do this C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.0\sbin>rabbitmqctl add_user XXXXXX YYYYYYY it gives me the following error... Error: unable to perform an operation on node 'rabbit@C001741998'. Please see diagnostics information and suggestions below. Most common reasons for this are: Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)