{"id":15180573,"url":"https://github.com/st-h/vertx-mongo-streams","last_synced_at":"2025-10-26T19:31:40.795Z","repository":{"id":57722980,"uuid":"60642131","full_name":"st-h/vertx-mongo-streams","owner":"st-h","description":"Helpers to stream data between vert.x ReadStream (e.g. HttpServerFileUpload), WriteStream (e.g. HttpServerResponse) and MongoDB AsyncInputStream and AsyncOutputStream.","archived":false,"fork":false,"pushed_at":"2020-10-13T07:53:17.000Z","size":105,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T23:03:51.433Z","etag":null,"topics":["gridfs","groovy","java","mongodb","mongodb-async-driver","readstream","vertx","writestream"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/st-h.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-07T19:54:48.000Z","updated_at":"2020-01-27T09:33:32.000Z","dependencies_parsed_at":"2022-08-25T11:01:54.928Z","dependency_job_id":null,"html_url":"https://github.com/st-h/vertx-mongo-streams","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st-h%2Fvertx-mongo-streams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st-h%2Fvertx-mongo-streams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st-h%2Fvertx-mongo-streams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st-h%2Fvertx-mongo-streams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/st-h","download_url":"https://codeload.github.com/st-h/vertx-mongo-streams/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238394323,"owners_count":19464583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gridfs","groovy","java","mongodb","mongodb-async-driver","readstream","vertx","writestream"],"created_at":"2024-09-27T16:22:58.601Z","updated_at":"2025-10-26T19:31:40.470Z","avatar_url":"https://github.com/st-h.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/st-h/vertx-mongo-streams.svg?branch=master)](https://travis-ci.org/st-h/vertx-mongo-streams)\n[![codecov](https://codecov.io/gh/st-h/vertx-mongo-streams/branch/master/graph/badge.svg)](https://codecov.io/gh/st-h/vertx-mongo-streams)\n[![BCH compliance](https://bettercodehub.com/edge/badge/st-h/vertx-mongo-streams?branch=master)](https://bettercodehub.com/)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.st-h/vertx-mongo-streams/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.st-h/vertx-mongo-streams)\n# GridFS stream helper for Vert.x 3.x and MongoDB async driver in Java and Groovy\nHelpers to stream data between vert.x ReadStream (e.g. HttpServerFileUpload), WriteStream (e.g. HttpServerResponse) and MongoDB AsyncInputStream and AsyncOutputStream.\n\n---\n\n# Important\nThis library is no longer maintained and will not receive any updates because of the following reasons:\n- the mongodb driver will remove support for callback style invocations\n- we no longer use GridFS to store binary data\n\n---\n\n# Prerequisites\n- Java 8\n- mongodb async driver \u003e= 3.10.0\n- vert.x \u003e= 3.4.0\n\n# Install\nmvn:\n```\n \u003cgroupId\u003ecom.github.st-h\u003c/groupId\u003e\n \u003cartifactId\u003evertx-mongo-streams\u003c/artifactId\u003e\n \u003cversion\u003e2.1.0\u003c/version\u003e\n```\n \ngradle:\n```\ncom.github.st-h:vertx-mongo-streams:2.1.0\n```\n\n## Upgrading from 1.x\n\nThe GridFSInputStream factory method `GridFSInputStream.create(vertx)` now requires the vertx instance as an argument. This is needed to ensure that the `drainHandler` of the vert.x `WriteStream` is called within the correct context. When the constructor is invoked, the current vertx context is stored and will be restored when needed. Therefore one should not try to cache the GridFSInputStream instance. Please see [this blog post](http://vertx.io/blog/an-introduction-to-the-vert-x-context-object/) for details about the vert.x context.\n\n# Usage\n\nSince vert.x 3.4.0 usage within java and groovy is identical.\n\n### Upload\nThe GridFSInputStream allows to directly Pump data from a vert.x ReadStream (e.g. HttpServerFileUpload) to MongoDB AsyncInputStream.\n\nJust create a new instance using the `GridFSInputStream.create()` method and use a `Pump` to transfer the data. Call the `end()` method when all data has been made available. The internal queue size can be changed using the `setWriteQueueMaxSize()` method.\n\nThis snippet creates a fully working http server that persists a file to GridFS: \n\n```java\nimport com.github.sth.vertx.mongo.streams.GridFSInputStream;\nimport com.mongodb.async.client.MongoClients;\nimport com.mongodb.async.client.MongoDatabase;\nimport com.mongodb.async.client.gridfs.GridFSBucket;\nimport com.mongodb.async.client.gridfs.GridFSBuckets;\nimport io.vertx.core.AbstractVerticle;\nimport io.vertx.core.Future;\nimport io.vertx.core.http.HttpServer;\nimport io.vertx.core.streams.Pump;\n\npublic class UploadVerticle extends AbstractVerticle {\n\n  private HttpServer httpServer;\n  \n  @Override\n  public void start(Future fut) {\n\n    // setup GridFS\n    MongoDatabase db = MongoClients.create().getDatabase(\"test\");\n    GridFSBucket gridFSBucket = GridFSBuckets.create(db, \"test-bucket\");\n\n    // setup the HttpServer\n    httpServer = vertx.createHttpServer().requestHandler(request -\u003e {\n\n      request.setExpectMultipart(true);\n\n      request.uploadHandler(fileUpload -\u003e {\n\n        // create a GridFSInputStream\n        GridFSInputStream gridFSInputStream = GridFSInputStream.create(vertx);\n\n        // when the upload has finished, notify the GridFSInputStream\n        fileUpload.endHandler(endHandler -\u003e gridFSInputStream.end());\n\n        // just use a Pump to stream all the data\n        Pump.pump(fileUpload, gridFSInputStream).start();\n\n        gridFSBucket.uploadFromStream(fileUpload.filename(), gridFSInputStream, (id, t) -\u003e {\n          if (t != null) {\n            // failed to persist\n            request.response().setStatusCode(500).end();\n          } else {\n            // sucessfully persisted with ID: id\n            request.response().end(\"uploaded: \" + id);\n          }\n        });\n      });\n    }).listen(8080, res -\u003e {\n        if (res.succeeded()) {\n          fut.complete();\n        } else {\n          fut.fail(res.cause());\n        }\n    });\n\n  }\n\n  @Override\n  public void stop(Future fut) {\n    httpServer.close( res -\u003e fut.complete());\n  }\n}\n```\n\n### Download\nThe GridFSOutputStream allows write to a vert.x WriteStream via the mongo drivers downloadToStream() method:\n\n```java\nGridFSOutputStream outputStream = GridFSOutputStream.create(httpServerResponse)\ngridFS.downloadToStream(objectId, outputStream, (bytesRead, t) -\u003e {\n\n    ...\n\n})\n```\n\n# Build\n## Integration Test\n\nIf you want to build this library yourself, the integration test requires a running mongodb on default port 27017. If you are using docker, you could just use the commands from `.travis.yml` to launch a docker container running a mongo instance and expose the default port:\n```\ndocker pull mongo\ndocker run -d -p 127.0.0.1:27017:27017 mongo\n```\n\n# Acknowledgments\n\nThanks to [antofar](https://github.com/antofar) for contributing an improved implementation of GridFSInputStream\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst-h%2Fvertx-mongo-streams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fst-h%2Fvertx-mongo-streams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst-h%2Fvertx-mongo-streams/lists"}