简体   繁体   English

用 Java 设计批量 REST API

[英]Designing a bulk REST API in Java

I have a problem with my appilication when am perfoming bulk update's and create's.在执行批量更新和创建时,我的应用程序出现问题。

I have very huge rest pay load which contains 1000 fields and with 10000 update at a time.我有非常大的剩余负载,其中包含 1000 个字段,一次更新 10000 个。 After submitting the request data will be save in db with jdbc procedure.提交请求后,数据将通过 jdbc 程序保存在 db 中。

Now here we are facing perfomance issue.现在我们面临着性能问题。

i have to design a bulk api to reslve this perfomance issue.我必须设计一个批量 API 来解决这个性能问题。

i searched existing bulk api by Sales force and Telerik.But not clear about their implemention.我通过 Sales force 和 Telerik 搜索了现有的批量 api。但不清楚它们的实现。

How do i design a my own bulk REST API in java for bulk update's and create's.我如何在 java 中设计我自己的批量 REST API 以进行批量更新和创建。

Which design patterns should i take into consideration?我应该考虑哪些设计模式?

It will be helpful for me, if any body could answer me.如果有任何机构可以回答我,这将对我有所帮助。

Thanks in advance.提前致谢。

An often used term in REST is "Collection Resource". REST 中一个经常使用的术语是“集合资源”。

Consider a system that stores invoices.考虑一个存储发票的系统。 The collection resource for them could have the URL他们的集合资源可以有 URL

/resources

while a single invoice with ID 123 could have the URL而 ID 为123的单个发票可能具有 URL

/resources/123

Adding a new invoice to the collection would be done using将使用以下方法向集合中添加新发票

POST /resources
Content-Type: application/json

{
  "customer": "CUS-123",
  "amount": 1.43,
  "paided": false
}

The server would store it and assign an ID to it.服务器将存储它并为其分配一个 ID。

To store more than one invoices in one request, it would make sense to post an array:要在一个请求中存储多个发票,发布一个数组是有意义的:

POST /invoices
Content-Type: application/json

[
  {
    "customer": "CUS-123",
    "amount": 1.43,
    "paided": false
  },
  {
    "customer": "CUS-456",
    "amount": 42.23,
    "paided": true
  }      
]

It would the responsibiltity of the server to recognize that now there are more than one invoice to store.服务器有责任认识到现在要存储的发票不止一张。

One example of such an API is ElasticSearch bulk update support: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html这种 API 的一个例子是 ElasticSearch 批量更新支持: https ://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

You can take some inspiration there.你可以在那里获得一些灵感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM