Reputation: 2533
I am looking to set custom objects in Application scope variables so that vertx has access to it across all micro-service requests. I couldn't find anything in Vertx documentation. In Java EE Servlet the code for similar feature is
getServletContext().getAttribute("application_data")
getServletContext().setAttribute("application_data", data);
Upvotes: 0
Views: 873
Reputation: 45319
For global data, you should simply use shared data. This has the additional benefit of being accessible across the cluster.
The following code uses a local map:
SharedData sd = vertx.sharedData();
LocalMap<String, String> map1 = sd.getLocalMap("mymap1");
map1.put("foo", "bar");
Reading is similarly easy:
String val = map1.get("foo");
The documentation is on this page
Upvotes: 3