发布于 2017-11-21 04:00:14 | 103 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Firefly 分布式游戏服务器端框架

Firefly是免费、开源、稳定、快速扩展、能 “热更新”的分布式游戏服务器端框架,采用Python编写,基于Twisted框架开发。它包括了开发框架和数据库缓存服务等各种游戏服务器基础服务,节省大量游戏开发的工作时间,真正做到让使用者把精力放在游戏玩法逻辑上。用它可以搭建自定义的分布式架构,只需要修改相应的配置文件即可。


Firefly v4.6.0 新增了OpenSSL引擎支持,命名参数SQL API,HTTP客户端连接泄露追踪,并修复了一些bug。完善了HTTP服务器与客户端Kotlin版数据库访问Kotlin版以及SSL/TLS配置文档。

使用OpenSSL引擎

现在Firefly支持JDK SSL引擎和OpenSSL引擎作为网络安全层。JDK SSL引擎是默认的。JDK8的SSL引擎不支持ALPN(应用层协议协商),HTTP2协议在TLS握手中需要ALPN的支持。如果您使用JDK8 SSL引擎则需要添加VM参数来设置一个引导程序alpn-boot.jar(具体情况参考SSL/TLS配置文档)。如果您在某些情况下无法修改VM参数,我们提供了支持ALPN的OpenSSL引擎支持,不需要任何VM设置就能启用HTTP2协议。例如:

public class OpensslHTTPsServer {      public static void main(String[] args) {          $.httpsServer(new DefaultOpenSSLSecureSessionFactory())           .router().get("/").handler(ctx -> ctx.end("hello world!"))           .listen("localhost", 8081);      }  }

访问 https://localhost:8081 ,浏览器将显示

hello world!

您也可以使用自己的证书文件,例如:

public class OpensslFileCertHTTPsServer {      public static void main(String[] args) throws IOException {          ClassPathResource certificate = new ClassPathResource("/myCA.cer");          ClassPathResource privateKey = new ClassPathResource("/myCAPriv8.key");          SecureSessionFactory factory = new FileCertificateOpenSSLSecureSessionFactory(                  certificate.getFile().getAbsolutePath(),                  privateKey.getFile().getAbsolutePath());            $.httpsServer(factory)           .router().get("/").handler(ctx -> ctx.end("hello world!"))           .listen("localhost", 8081);      }  }

注意:OpenSSL私钥文件必须使用PKCS8格式,您可以使用“openssl pkcs8”命令进行格式转换,例如:

openssl genrsa -out myCA.key 2048  openssl req -new -x509 -key myCA.key -out myCA.cer -days 36500  openssl pkcs8 -topk8 -inform PEM -outform PEM -in myCA.key -out myCAPriv8.key -nocrypt

命名参数SQL API

命名参数SQL增加了代码的可读性。当我们使用命名参数SQL的时候,可以使用map或者javabean来替换占位符。

Java版例子:

@Test  public void testInsert() {      String sql = "insert into `test`.`user`(pt_name, pt_password) values(?,?)";      Mono<Long> newUserId = exec(c -> c.insert(sql, "hello user", "hello user pwd"));      StepVerifier.create(newUserId).expectNext(size + 1L).verifyComplete();        String namedSql = "insert into `test`.`user`(pt_name, pt_password) values(:name, :password)";      Map<String, Object> paramMap = new HashMap<>();      paramMap.put("name", "hello user1");      paramMap.put("password", "hello user pwd1");      newUserId = exec(c -> c.namedInsert(namedSql, paramMap));      StepVerifier.create(newUserId).expectNext(size + 2L).verifyComplete();        User user = new User();      user.setName("hello user2");      user.setPassword("hello user pwd2");      newUserId = exec(c -> c.namedInsert(namedSql, user));      StepVerifier.create(newUserId).expectNext(size + 3L).verifyComplete();  }

Kotlin版例子:

@Test  fun testInsert() = runBlocking {      val newUserId = exec {          it.asyncInsert<Long>("insert into `test`.`user`(pt_name, pt_password) values(?,?)",                  "hello user", "hello user pwd")      }      assertEquals(size + 1L, newUserId)        val namedSQL = "insert into `test`.`user`(pt_name, pt_password) values(:name, :password)"      val newUserId2 = exec {          it.asyncNamedInsert<Long>(namedSQL, mapOf("name" to "hello user", "password" to "hello user pwd"))      }      assertEquals(size + 2L, newUserId2)        val newUserId3 = exec {          it.asyncNamedInsert<Long>(namedSQL, User(null, "hello user", "hello user pwd", null))      }      assertEquals(size + 3L, newUserId3)  }

更新日志:

  1. 网络工具增加OpenSSL引擎支持。

  2. 增加命名参数SQL API。

  3. 完成了Kotlin相关文档。

  4. 新增了SSL/TLS配置文档。

  5. 修复了使用请求Accept头匹配router时,router优先级错误的问题。

  6. 增加了默认的bad message监听器。

  7. 增加了HTTP client连接泄露追踪。



历史版本 :
Firefly 4.7.0 正式版发布,增加新的 WebSocket APIs
Firefly 4.6.0 正式版发布,新增OpenSSL引擎支持
Firefly 4.5.0 正式版发布
Firefly 4.0.21 发布,Java 的 Web 框架
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务