How to toggle Multiple Features in Spring Boot Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everyone and welcome to daily code buffer in this video we are going to see how we can have multiple features developed in our Java application and how to maintain all those features for your release Cycles as well so whenever we working with the application we have to maintain the different features and all those different features have to be maintained based on the different production life cycles right so in one of the release one feature is going in the next release next feature is going and in the middle of that you got an issue in the feature one and you need to to that and you need to disable that feature and lot of things that can happen in production right so for that what if I can tell you that there is a simple Library available which can help us to maintain all those features and we can enable and disable those features whenever we want according to the requirements so for that we are going to use the ff4j library for Java that is the feature flipping library for Java and this will allow us to maintain the different features that we are going to develop so let's understand the difference strategies available using the ff4j and how we can Implement in our springboard application so here you can see that there are different types of strategies available and we can use any of those strategies and we can Implement in our application so all those strategies requires a different implementation for it and all the strategies have its purpose when to use what let's go through the strategies and when we can use these type of strategies okay it's really easy to implement and for all the things there is a documentation also available like how to use that so I'll link that also in the description below for you to check out and we will also go through one of the examples as well similarly you can Implement for the others as well so the first one is office ours flipping strategy so in the office hours flipping strategy what you can do is you can Define the office hours okay and within those office hours only if you want some features to be enabled you can do that using the office hours flipping strategy suppose you want a feature that is only available during the office hours suppose that is 9 to7 then you can Define that particular strategy and that particular feature will be only enabled during that hours for rest of the hours it will be disabled so that is the first office hour flipping strategy the next is the region flipping strategy in this region flipping strategy you will Define the list of regions and if any request or anything or your deployment is been done in that particular region for that only that particular feature will be enabled so suppose if I'm enabling any feature for Europe region right so for that Europe region I can Define that this particular feature is for this all region that is Europe and all those regions we can Define and it will decide for every request that is that particular region Europe or not if not it will disable that and it won't be enabled so this is how the region flipping strategy will work the next is overriding strategy so suppose if you want to override any of the existing strategies applied then we can use the overriding flipping strategy the next is the client filter strategy Suppose there are multiple clients using your application right and if you are creating any of the features for any particular clients then we we can Define the client filter strategy in this strategy itself whenever we are developing the feature we will Define that okay this particular feature is only be available for this much clients you will Define all those clients and for those clients only for those hosts only this particular feature will be developed that feature will be enabled for rest of the clients it will be disabled the same is for the server filter strategy as well in this particular list you will Define the servers available so suppose if you're are developing a strategy for some of the servers then you can Define that okay for all these servers I am enabling this particular feature for rest of the servers you are disabling it if you're not providing any servers then it will by default take the existing server and for that it will enable the feature okay so this is the server filter strategy the next is the ponderation flipping strategy so in this ponderation flipping strategy what you can do is you can Define your percentage how much percentage you want to enable this feature for a different types of user okay so that's a dark strategy you can Define so suppose you want a particular feature to be only enabled for 10% of users okay whatever request you getting so for that you will Define the percentage and based on that percentage this particular flipping strategies will be enabled suppose if you want that particular feature to be enabled for some particular users and for that particular users also you want to Define for 10% or 20% of the time this feature should be enabled to check your AB testing or whatever testing you need to do okay beta testing or whatever so at that time you will Define the ption flipping strategy and based on that your feature will be enabled or disabled the next is the release date flipping strategy so it's a straightforward strategy where you will Define a date and time and based on that date and time that particular strategies will be enabled and before that that will be disabled and we can change that as well okay so that's the release date flipping strategy the next and very important one is the expression flipping strategy now this particular expression flipping strategy is used to mix and match the different strategies available okay suppose I want to enable a particular feature in only Europe region and for only 10% of users okay so at that time I can use the region flipping strategy and ponderation flipping strategy using the end operator and using that expression and I can enable that particular feature okay so there is and or and not operators those expressions are there we can use those expressions and we can enable the expression flipping strategy based on the other flipping strategies available okay so these are the general strategies available and we can use any of the strategies to implement in our application based on the features that you are developing I will add the documentation link as well and it is very easy to implement so here we have taken one example and we are implementing the release date flipping strategy so here you can see that our uh springboard application is there and we have done a very simple program here okay here you can see see that it's our spring boot web application we have the ACC dependency we have the spring starter web dependency and the test dependencies okay on top of that we have added two dependencies that is the ff4j spring boot starter that is a spring boot starter dependency for the ff4j and ff4j web dependency okay these are the two dependencies that we have added here in our application and what we have done is this is our class this is our main class you can see that this is f 4J demo application and this is the main method okay what we have done is we need the object of ff4j so we have defined the ff4j config here this is the ff4j config class we have added as a configuration and here you can see that I have defined the feature okay by default ff4j works on the inmemory database okay but if you're working with inmemory database it will not remember which feature were enabled which feature were disabled okay the moment the application restarts everything will go so by default it stores everything in memory but if you want to store all those information as well like in particular server which which features were enabled what features were disabled and where then we can use the database as well we can configure the FF 4G to use the database like R is like mongodb your SQL to store all those features as well and we can flip those features whenever we want so that configuration is also available using the ff4j and you can see I have just defined one feature over here that the name of the feature I given as new feature okay that a simple thing I defined and I wanted to create the bean of ffj class because this is something this will act as a main class and we have to use this class okay so here I'm creating the method that is f4j that will return the object of f fure within that I have created the object and I have defined the strategy that is the flipping strategy and what flipping strategy I'm using I'm using release date flip strategy so here this flipping strategy you can see it has been implemented by by 11 different classes that is abstract flip strategy Blacklist client filter dark launch expression office RS ponderation region flip so whatever we discuss all those are available so we can use anything based on the different classes the input parameters are different and we have to pass those input parameters to make that it works and accordingly we have a check method to check if that particular feature is enabled or not so here we have defined the release date flipping strategy and we can Define the start dat as well suppose I'm defining 2023 10 24 today is 24th dat right and I'm defining this as a three that is 1545 okay this is the time that I'm defining and after that what I'm doing is I'm defining a feature and that feature I have defined that is a new feature right that I have defined this feature and I have enabled this feature and I have for this particular feature I Define the strategy that is flipping strategy okay so for a feature I will Define the strategy and I am creating a feature feature within the ff4j class and I'm returning the object okay simple thing now within this command line Runner what I'm doing is I'm checking okay if ff4j whatever the object is there right check if ff4j doc config new feature so if that particular feature is enabled or not so this line will check if that feature is Avail is enabled then it will print feature is enabled else it will print feature is disabled simple things so with this check method it will check the availability of the feature okay so right now it's 343 so we'll run the application till then it should print oops new feature is disabled the moment it is 345 based on the date that we have provided it should start saying that the feature is enabled okay so it will internally check everything within the server you do not have to restart or anything okay so let me just start the server okay currently it is 3:44 and our time is 3:45 so let's start the server and we'll see till that it will print oops new feature is disabled and post that it will print okay we have some error idy stop the process okay so Port 880 is currently new so let me just stop that and restart the application what I'll do is I'll just Define server. Port equals to 881 okay so this should solve our issue okay so now you can see that it is saying oops new feature is disabled okay because it's 345 and the moment 345 you can see it has started printing new feature is enabled okay so now you can see that for the moment it was printing till the time was not there till the release date was not there it was printing oops new feature is disabled because the feature was disabled the moment it hit the time it was enabled okay it will constantly check and it will enable the feature so this way you can see that the release feature flipping strategy is working completely fine and you can Implement whatever strategies that we want based on the different classes provided and if you want to mix and match we can also use the the expression flipping strategy and we can mix those as well so you can see it's very easy to implement and if you want to store each and everything within database we can add the configuration for DB as well which will store each and everything within the DB not in in memory I will add the link for this as well you can see these flipping strategies are available and all the details are available how to use those you can see it's office flipping strategy and uh region flipping strategy you can see there are regions provided okay so all these particular things are there it's very easy to implement and based on the requirement we can Implement so that was a quick video about how to implement different features how to flip those different features in your spring board application if you enjoyed this video then give us a thumbs up and subscribe to my channel for the upcoming videos you can also click on join button to join my channel and support me I will see you in the next video till then Happy cording bye-bye
Info
Channel: Daily Code Buffer
Views: 6,568
Rating: undefined out of 5
Keywords: spring boot, java, spring, spring framework, web development (interest), ff4j, ff4j spring boot, ff4j spring boot tutorial, ferature flipping in spring boot application, ferature toggles, daily code buffer
Id: 0dSsr3mZrKI
Channel Id: undefined
Length: 11min 50sec (710 seconds)
Published: Thu Oct 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.