非Docker环境下使用dapr (windows实战helloworld)

这个架构图很清晰,通过这个helloworld可以对dapr有个感性的认识,整个过程也就半小时吧,建议实操一把。

  1. 安装dapr
    参考官网:Install the Dapr CLI | Dapr Docs
    powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"
    
  2. 初始化

    dapr init --slim
  3. 创建Node.js后端微服务
     

    git clone https://github.com/dapr/samples.git
    cd samples/hello-dapr-slim

    实例使用了Express,代码很简单
     

    app.post('/neworder', bodyParser.json(), (req, res) => {
        const data = req.body.data;
        const orderId = data.orderId;
        console.log("Got a new order! Order ID: " + orderId);
        res.status(200).send("Got a new order! Order ID: " + orderId);
    });

  4. 通过Dapr运行Node.js微服务

    先安装依赖

    npm install

    用Dapr运行,感觉像托管给Dapr,增加了一层端口
     

    dapr run --app-id nodeapp --app-port 3000 --dapr-http-port 3500 node app.js

  5. 测试微服务
    测试方法很多,就是Post一个Http请求,例如用cmd命令行:
     

    dapr invoke --verb POST --app-id nodeapp --method neworder --data "{\"data\": { \"orderId\": \"41\" } }"

    也可以用PostMan, VsCode的Rest Client插件

  6. 查看微服务
     

    dapr list

     可以看到Dapr还支持gRPC

  7. 清理微服务
     

    dapr stop --app-id nodeapp
    打赏 2¥

参考:How-To: Run Dapr in self-hosted mode without Docker | Dapr Docs

小结:Slim方式初始化功能有限,还需要自己配置状态管理,适合没有Docker环境的小伙伴

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huajian2008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值