I would split the bonk into 2 categories: mental and physical. Regarding the first, just remember rule #5 of the Velominati: Hard The F@#$ Up. I had HTFU sharpied on the top tube of one of my bikes in the past as a constant reminder.
Regarding the physical aspect, it primarily comes down to food and hydration...
My go-to snack is a peanut butter banana "sandwich". Take a piece of bread, generously smear PB on one side, sprinkle a little salt on the PB, slice a banana in half, wrap the bread around the banana half. (Note: Technically, I think this would be classified as a hotdog, not a sandwich?)
This snack will give you a good balance of fats, protein, and roughly 30g of slower releasing carbs. And if my math is correct, one of these small "sandwiches" will actually have more electrolytes (sodium, potassium, chloride, calcium, magnesium, phosphate) than a medium-sized bottle of Gatorade.
I would recommend going to an online calorie calculator and figuring out how many calories you will be burning each hour. Try to replace ~75% of these calories with one of my PB-banana-hotdogs (patent pending) as you ride.
Though caffeine will give you more energy, I am not a huge fan of it on longer rides. In my opinion, caffeine only offers a temporary solution, as the caffeine will eventually wear off, causing you to hit the wall again. On longer rides, I might drink a large glass of tea (hot or iced) in the morning to get me going, and maybe some coffee to get me through the last hour of a ride.
If you must have caffeine during the ride, chocolate covered coffee beans are a good way to regulate your caffeine consumption. Eat one every 30 minutes to get a slow, consistent release of caffeine.
Drink a ton of water, especially if you a sweating. Dehydration is no joke. You can determine whether you are drinking enough water by looking at your piss. It should be a very light yellow color.
If you find that your muscles are getting sore, consider increasing your cadence. Shoot for 90rpm. This will help you utilize your slow twitch muscle fibers, saving your fast twitch fibers for when you need short bursts of speed.