Handwave and summarise the boring stuff
I have struggled with a similar problem. I like to make my world immersive and give distinct characteristics to every NPC my group encounters. However it can lead to the players talking to an NPC for 10 minutes to purchase a meal.
As long as everyone is having fun this isn't a problem. However as you have pointed out some players can get bored of the extended dialogue. So what I tend to do is role play the first encounter with an NPC. Give the tavern keeper a personality when they first enter. Once the character is established however I won't play out the scene unless the players are trying to do something interesting with the conversation. Instead I simply state "you go a buy a meal from the bar, she charges you 3cp".
If the conversation is going to be mundane don't bother playing it out entirely. Keep your deep dialogue and extended scenes for the important stuff. This has the added bonus of reducing the number of distinct characters you need play/remember.
When the important information runs out
If a conversation starts out important and you want to play it at the table you can still use some similar techniques.
Mid-conversation should the PCs have gathered all the important information from the NPC simply tell them:
"You spend another 15 minutes talking to the sailor but learn nothing else interesting, except that he has a tattoo of a mermaid in a place he won't show you."
When talking to a powerful NPC, a Lord or ruler of some kind you can say things like:
"The King appears visibly frustrated by your continued questions, you recognise you only have one or two more before he tells you to leave"
If they don't take the hint to wrap it up, or this is too aggressive, remember that NPCs are people too and probably have other things to do.
"I'm afraid I have to go, never enough hours in the day for all the things I have to do"
Then have the NPC simply leave.
You also have the option to have another NPC interrupt them. If the NPC is a shop keeper they will have other customers, peasants will have children or friends, even the guard could show up to accuse them of loitering.
What about when the NPC has no reason end the conversation?
Sometimes you will find yourself in a situation where none of the above techniques will be logical. The hermit in the swamp who has nothing but time to talk to adventurers for example. In these situations you can take the opposite approach, bore the characters into ending it themselves.
PC: "How long have you been here?"
Hermit: "Well I first arrived on a moonswept night... the swamp was beautiful..."
DM: The Hermit launches into a 20 minute description of his arrival to the swamp.
PC: "But how long ago?"
Hermit: begins the same story...
With this approach you need to make the passage of time clear. The PCs are burning daylight talking to the NPC. This means they might not have time to get to that important MacGuffin tonight.
How to tell when to handwave
You mentioned in a comment on another answer this was something you were struggling with, I'll attempt to provide some advice.
From the GM side its pretty easy, if the party has gathered all the information you intend to give them then it's safe to handwave. Though you should be careful not to handwave away conversations that are entertaining and the entire table is invested in.
For example I had a very Australian NPC (I'm Australian too and I slipped with my accent when introducing the NPC) that the party thought was hilarious. His entire point was to give them directions to the important location in town. However I let the players continue talking to him until I ran out of Australian jokes at which point I had him leave to return to work.
The harder part is when you know there is still information to gather but the players have begun checking out of the conversation. It is hard to give advice for this as it will vary from group to group but some things to watch for are: players leaning back on their chair, players not joining in the conversation, phones or other distraction being looked at, and a reduction in the role playing effort.
At this point you can reduce the conversation to a dice roll. Have them role a social check and base the DC on how well the conversation has been going. On a success you give them all the important information in the handwaved summary. On a fail they may only get some or even none of it.
You want to use GM fiat and handwaving to indicate that the conversation continued but that they had all the important information. The players should trust that you have given them everything they could have gotten through continued conversation.