我有一个包含Lighthouse种子节点的Akka.NET集群和另外两个运行actor系统的节点.当我尝试在我的一个群集节点上正常关闭时,我想看到至少有一个其他节点看到有关该节点离开的消息,并且所有群集节点最终都排除了节点列表的离开节点.
一旦完成了这一点,我希望我能够关闭节点,而其他两个节点不会因为无法连接到关闭的节点而疯狂.
我现在拥有的是一个包含在TopShelf应用程序中的控制台应用程序:
class ActorService : ServiceControl
{
private ActorSystem _actorSystem;
public bool Start(HostControl hostControl)
{
_actorSystem = ActorSystem.Create("myActorSystem");
var cluster = Cluster.Get(_actorSystem);
cluster.RegisterOnMemberRemoved(_Terminate);
return true;
}
public bool Stop(HostControl hostControl)
{
var cluster = Cluster.Get(_actorSystem);
cluster.Leave(cluster.SelfAddress);
return true;
}
private void _Terminate()
{
_actorSystem.Terminate();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要内容:
class Program
{
static int Main(string[] args)
{
return (int) HostFactory.Run(x =>
{
x.UseAssemblyInfoForServiceInfo();
x.RunAsLocalSystem();
x.StartAutomatically();
x.Service<ActorService>();
x.EnableServiceRecovery(r => r.RestartService(1));
});
}
}
Run Code Online (Sandbox Code Playgroud)
当单步执行Stop功能时,我看不到任何有关节点离开其他节点的消息.但是,当函数返回时,其他节点开始喷出异常.
Akka.NET Gitter频道的用户说:
即使没有TopShelf我也必须说,在webhost终止后使用纯ASP.NET核心项目,我观察到同样的事情.
我可以添加什么让其他节点收到有关节点离开的消息?
我在我的Node.JS应用程序中使用mongoose和TypeScript.populate从数据库中获取数据时,我在很多地方使用mongoose .
我面临的问题是我不知道如何键入我的模型,以便属性可以是ObjectId,也可以填充来自其他集合的数据.
我试图在我的模型类型定义中使用union类型,这似乎是TypeScript提供的类似于以下内容的东西:
interface User extends Document {
_id: Types.ObjectId;
name: string
}
interface Item extends Document {
_id: Types.ObjectId;
// Union typing here
user: Types.ObjectId | User;
}
Run Code Online (Sandbox Code Playgroud)
我的模式只将属性定义为带有ref的ObjectId.
const ItemSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: "User", index: true }
})
Run Code Online (Sandbox Code Playgroud)
示例:
所以我可能会这样做:
ItemModel.findById(id).populate("user").then((item: Item) => {
console.log(item.user.name);
})
Run Code Online (Sandbox Code Playgroud)
这会产生编译错误:
[ts] Property 'name' does not exist on type 'User | ObjectId'.
Property 'name' does not exist on type 'ObjectId'.
Run Code Online (Sandbox Code Playgroud)
我想在向服务器后端发出 HTTP 请求时使用实际的错误响应来练习我的 JavaScript 错误处理代码。因此,我正在寻找一种简单的方法来模拟响应,使用给定的状态代码、标头、响应正文等。
通过msw包,我可以设置一个服务工作人员来捕获请求并生成响应:
import { rest } from "msw";
const BASE_PATH = "https://localhost:3000";
export const handlers = [
rest.get(`${BASE_PATH}/hello`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json({ data: "Hello!" }));
}),
rest.get(`${BASE_PATH}/error`, (req, res, ctx) => {
return res(ctx.status(400), ctx.json({ message: "Bad request" }));
})
}
Run Code Online (Sandbox Code Playgroud)
然而,这需要一些代码来连接。如果 Chrome 开发工具中有一些功能可以让我修改响应,就像我可以阻止对某些路由的请求一样,那就更好了。
在浏览器中模拟 HTTP 请求响应的最简单方法是什么?
自Chrome版本66以来,如果用户之前没有访问过我的网站,那么我网站上应该自动播放的视频可能无法播放Chrome.
<video src="..." autoplay></video>
Run Code Online (Sandbox Code Playgroud)
如何检测视频自动播放是否已禁用?我能做些什么呢?
我有多个图像要加载,我把它们放在一个数组中。
在循环中,我在加载图像时增加一个计数器。
当这个计数器等于我的图像的数组长度时,我想删除加载指示器。
我不知道为什么,那不起作用。
new Vue({
el: "#app",
created() {
let imageLoaded = 0;
for (const imageSrc of this.imagesToPreload) {
if (imageLoaded === this.imagesToPreload.length) {
console.log("Done !");
this.loading = false;
}
const img = new Image();
img.src = imageSrc;
img.onload = () => {
imageLoaded++;
console.log(imageLoaded);
};
}
},
data() {
return {
isLoading: true,
imagesToPreload: [
"https://placeimg.com/1280/800/any",
"https://placeimg.com/1280/800/any",
"https://placeimg.com/1280/800/any"
]
};
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div v-if="isLoading">Loading...</div>
</div>Run Code Online (Sandbox Code Playgroud)
为什么 buildspec 文件支持多个构建阶段?install, pre_build, build, post_build? 如果我将所有构建步骤都放在一个阶段,我是否做错了什么?除了保持某种结构之外,有什么非常有用的东西吗?
我尝试image-slice使用 Node js 分割成多个部分。
我尝试安装npm i image-to-slices, sudo port install cairo,npm i canvas但brew install pkg-config cairo pango libpng jpeg giflib仍然require node-canvas在服务器端显示错误 node.js
这是我尝试切片图像:
var imageToSlices = require('image-to-slices');
exports.sliceImage=(request, response)=>{
var lineXArray = [100, 200];
var lineYArray = [100, 200];
var source = './public/images/Bitmap001.png'; // width: 300, height: 300
imageToSlices(source, lineXArray, lineYArray, {
saveToDir: './public/images/bit001.png'
}, function() {
console.log('the source image has been sliced into 9 sections!');
});
}//sliceImage
Run Code Online (Sandbox Code Playgroud)
控制台输出错误: …
我必须使用 Node.JS 和 TypeScript 构建一个 rest API。我正准备用 Express,但看起来 Koa、Fastify 和 Hapi 可以提供更好的最新体验。
那么,在 2021 年使用 node 和 TS 构建 rest api 的现代选择是什么?
谢谢!
我想用以下格式在打字稿中创建动态数组
const display = [
{ id: 1, displayName: "Abc1" },
{ id: 2, displayName: "Abc2" },
{ id: 3, displayName: "Abc3" }
]
Run Code Online (Sandbox Code Playgroud)
我尝试过以下代码
const [display, SetDisplay] = useState([])
function createData(id: number, name: string) {
return { id, name };
}
SetDisplay(display.push(createData(1, "Abc1")))
Run Code Online (Sandbox Code Playgroud)
但无法将数据推送到变量中display。出现错误,例如
Argument of type '{ id: number; result: string; }' is not assignable to parameter of type 'never'.
Run Code Online (Sandbox Code Playgroud)
任何解决此问题的信息都会有所帮助。