我已经阅读过Scala,通常建议使用Traits而不是Abstract类来扩展基类.
以下是一个很好的设计模式和布局吗?这是Traits如何取代Abstract?
今天,我经常尝试在我的Phoenix应用程序中混合使用ecto.migrate,并且出乎意料地发现了以下错误:
warning: could not find repositories for application :adah.
You can avoid this warning by passing the -r flag or by setting the
repositories managed by this application in your config files:
config :adah, ecto_repos: [...]
The configuration may be an empty list if it does not define any repo.
** (Protocol.UndefinedError) protocol Enumerable not implemented for :ok
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:116: Enumerable.reduce/3
(elixir) lib/enum.ex:1486: Enum.reduce/3
(elixir) lib/enum.ex:609: Enum.each/2
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
Run Code Online (Sandbox Code Playgroud)
我的代表是:
phoenix_ecto: 3.0.0-rc.0
ecto: 2.0.0-rc.0 …Run Code Online (Sandbox Code Playgroud) 如果我像这样创建一个日志记录演员
val logger: ActorRef =
actorSystem.actorOf(Props(new Logger()))
Run Code Online (Sandbox Code Playgroud)
并且记录器由于异常而重新启动,我的记录器停止写入磁盘.
我一直在发短信 logger ! msg
假设当主管重新启动我的日志记录演员时,ActorRef没有更新,我是否正确?
我正在创建一个值为整数-17678的HBASE表.但是当我从pheonix中检索它时,它给了我一个不同的正值.RowKey是一个复合rowkey,rowkey没有问题.
Hbase插入:
public class test
{
public static void main(String args[])
{
Configuration config = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("TEST"));
Integer i=-17678;
try
{
Put p = new Put(Bytes.toBytes("rowkey"));
p.addColumn(Bytes.toBytes("test"),Bytes.toBytes("test"),Bytes.toBytes(i));
table.put(p);
}
finally
{
table.close();
connection.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
凤凰检索:
从TEST中选择CAST("Value"AS INTEGER);
+------------------------------------------+
| TO_INTEGER(test."Value") |
+------------------------------------------+
| 2147465970 |
+------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
这里有什么不对吗?还是凤凰问题?
有一些用Phoenix制作的API,API与JSON一起使用.
但是,当您测试它并发送JSON curl失败时,因为Phoenix不会将请求解析为JSON.您需要显式添加application/json标头curl.我想让它更强大,并告诉Phoenix总是将所有请求解析为JSON.
有没有办法迫使Phoenix总是将请求视为JSON并将其解析为JSON?
UPDATE
我尝试使用插件来设置@AbM建议的请求标头,并在Router中使用以下代码:
def set_format conn, format do Plug.Conn.put_private conn, :phoenix_format, format end
def put_req_header conn, {key, value} do Plug.Conn.put_req_header conn, key, value end
pipeline :api do
plug :put_req_header, {"accept", "application/json"}
plug :put_req_header, {"content-type", "application/json"}
plug :set_format, "json"
plug :accepts, ["json"]
end
Run Code Online (Sandbox Code Playgroud)
请求已使用CURL
curl -X POST http://localhost:4000/api/upload -d '{"key": "value"}'
Run Code Online (Sandbox Code Playgroud)
连接看起来像:
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
before_send: [#Function<1.93474994/1 in Plug.Logger.call/2>,
#Function<0.119481890/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>],
body_params: %{"{\"key\": \"value\"}" => nil},
cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: …Run Code Online (Sandbox Code Playgroud) 我正在使用凤凰框架,所以:
我在/web/static/js/socket.js上有以下代码
chatInput.on("keypress", event => {
if (event.keyCode === 13) {
channel.push("new_msg", {body: chatInput.val()}); //im want to pass @conn here
chatInput.val("")
}
});
Run Code Online (Sandbox Code Playgroud)
和/ web/channels/room_channel:
use Phoenix.Channel
defmodule fooBar do
def handle_in("new_msg", %{"body" => body}, socket) do #and get conn here
broadcast! socket, "new_msg", %{body: body}
{:noreply, socket}
end
end
Run Code Online (Sandbox Code Playgroud)
我需要在room_channel得到conn.我怎么能在socket.js传递它?
我目前正在使用KITE API + AVRO来处理HBase的java对象.但由于各种问题,我正在寻找替代方案.我一直在读:
凤凰
原生Hbase Api.
但还有更多选择吗?.我们的想法是将Java对象保存并加载到Hbase,并在Java应用程序中使用它们.
我想初始调用initConnection,它调用getData,它以递归方式调用自身,直到需要刷新connection-id,然后调用initConnection.
@tailrec private def initConnection(): Unit =
{
val response: Future[Response] = initHeaders(WS.url(url)).post(auth)
response.onSuccess {
case resp => getData(20, resp.asInstanceOf[Response].header("connectionID").get)
}
response.onFailure {
case resp => initConnection()
}
}
@tailrec private def getData(requestsLeft: Int, sessionId: String): Unit =
{
if (requestsLeft == 0)
{
initConnection()
}
else
{
//send request and process data
getData(requestsLeft - 1, sessionId)
}
}
Run Code Online (Sandbox Code Playgroud)
我在IntelliJ中得到一个'不在尾部位置的递归调用'错误,仅用于initConnection函数.是不是可以在两个函数之间使用尾递归?或者它只与我的未来[回应]有关?
我也尝试删除未来[回应]
@tailrec private def initConnection(): Unit =
{
val response: Response = initHeaders(WS.url(url)).post(auth).value.get.get
getData(20, response.header("ConnectionID").get)
}
Run Code Online (Sandbox Code Playgroud)
并获得有关initConnection不包含递归调用的错误.然而,这显然是无限递归的
我想从对象列表中获取第一个索引对象.这是示例对象:
[%VendorModel{__meta__: #Ecto.Schema.Metadata<:loaded>,
cameras: #Ecto.Association.NotLoaded<association :cameras is not loaded>,
config: %{"auth" => %{"basic" => %{"password" => "12345",
"username" => "admin"}},
"snapshots" => %{"h264" => "h264/ch1/main/av_stream",
"jpg" => "Streaming/Channels/1/picture"}}, exid: "ds-2cd2032-i", id: 332,
name: "DS-2CD2032-I",
vendor: #Ecto.Association.NotLoaded<association :vendor is not loaded>,
vendor_id: 6},
%VendorModel{__meta__: #Ecto.Schema.Metadata<:loaded>,
cameras: #Ecto.Association.NotLoaded<association :cameras is not loaded>,
config: %{"auth" => %{"basic" => %{"password" => "12345",
"username" => "admin"}},
"snapshots" => %{"h264" => "h264/ch1/main/av_stream",
"jpg" => "Streaming/Channels/1/picture", "mjpg" => "/",
"mpeg4" => "mpeg4/ch1/main/av_stream"}}, exid: "ds-2cd2612f-i", id: 2911,
name: …Run Code Online (Sandbox Code Playgroud)